不支持每种类型的多个对象集。 对象集IdentityUsers’和用户都可以包含类型的实例

对象集IdentityUsers’和用户都可以包含net类型的实例

但是我试图创建一个多对多的关系,比如这个教程显示了get-started-with-ef-using-mvc

但是我得到了这个错误=> Multiple object sets per type are not supported. The object sets 'IdentityUsers' and 'Users' can both contain instances of type 'bugs_b_gone.Models.ApplicationUser' Multiple object sets per type are not supported. The object sets 'IdentityUsers' and 'Users' can both contain instances of type 'bugs_b_gone.Models.ApplicationUser'

我在项目类中有一个属性,所以创建项目的用户是管理员但是现在管理员必须创建用户并将其分配给项目

 public class Project { [Key] public int ProjectID { get; set; } //public int AdminID { get; set; } [Required] [StringLength(50, ErrorMessage = "Title cannot be longer than 50 characters.")] [Column("Title")] [Display(Name = "Title")] public string Title { get; set; } [Required] public string Description { get; set; } //public int MemberID { get; set; } //public virtual ApplicationUser User { get; set; } public virtual ICollection Bugs { get; set; } // veel op veel public virtual ICollection User { get; set; } } 

现在是IdentityModel.cs

 public class ApplicationUser : IdentityUser { public virtual ICollection Projects { get; set; } public virtual ICollection Bugs { get; set; } public virtual ICollection Comments { get; set; } } public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() : base("DefaultConnection") { } public DbSet Projects { get; set; } public DbSet Bugs { get; set; } public DbSet Comments { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasKey(l => l.UserId); modelBuilder.Entity().HasKey(r => r.Id); modelBuilder.Entity().HasKey(r => new { r.RoleId, r.UserId }); //modelBuilder.Conventions.Remove(); /* modelBuilder.Entity() .HasOptional(f => f.AssignedToID) .WithRequired(s => s.Bug);*/ modelBuilder.Conventions.Remove(); modelBuilder.Entity() .HasMany(c => c.User).WithMany(i => i.Projects) .Map(t => t.MapLeftKey("ProjectID") .MapRightKey("Id") .ToTable("ProjectUser")); } public System.Data.Entity.DbSet IdentityUsers { get; set; } } 

你的问题是这一行:

 public System.Data.Entity.DbSet IdentityUsers { get; set; } 

IdentityDbContext已包含类型为IDbSetUsers属性。 您不需要为ApplicationUser添加自己的DbSet 。 删除该行,你很好。