我正在使用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) 我有一个 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)
在我的编辑视图中,我尝试将 …