小编Ram*_*mar的帖子

IdentityUserLogin <string>'在添加迁移时需要定义主键错误

我正在使用2种不同的Dbcontexts.我想使用2个不同的数据库用户和mycontext.虽然这样做我收到错误实体类型'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin'需要定义主键.我认为IdentityUser有问题请建议我在哪里可以更改我的代码,以便我可以添加迁移.

我的Dbcontext类:

 class MyContext : DbContext
{
    public DbSet<Post> Posts { get; set; }
    public DbSet<Tag> Tags { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<PostTag>()
            .HasKey(t => new { t.PostId, t.TagId });

        modelBuilder.Entity<PostTag>()
            .HasOne(pt => pt.Post)
            .WithMany(p => p.PostTags)
            .HasForeignKey(pt => pt.PostId);

        modelBuilder.Entity<PostTag>()
            .HasOne(pt => pt.Tag)
            .WithMany(t => t.PostTags)
            .HasForeignKey(pt => pt.TagId);
    }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public AppUser User {get; …
Run Code Online (Sandbox Code Playgroud)

entity-framework

58
推荐指数
3
解决办法
4万
查看次数

模型绑定对象集合作为 ASP.Net Core MVC 中模型的一个属性

我有一个 PostEditViewModel 类

 public class PostCreateViewModel
{
    public int PostId { get; set; }
    public string Title { get; set; } 
    public string Body { get; set; } 

    public string Descrition { get; set; } 
    public string Category { get; set; }

    public List<IFormFile> Images { get; set; } 
    public List<ImagePath> ExistingPhotoPaths { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

和 ImagePath 类

public class ImagePath
{
    public int ID { get; set; }
    public string Path { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在我的编辑视图中,我尝试将 …

c# asp.net-mvc asp.net-core

4
推荐指数
1
解决办法
3829
查看次数

标签 统计

asp.net-core ×1

asp.net-mvc ×1

c# ×1

entity-framework ×1