VS 2013 Controller Scaffolding Fails for the ApplicationUser Model (Multiple object sets per type are not supported)

后端 未结 8 2436
死守一世寂寞
死守一世寂寞 2020-12-08 11:07

In a VS 2013 RTM, MVC 5 project with EF 6, I tried to scaffold a controller based on the ApplicationUser (default with individual accounts authentication). Both Applic

8条回答
  •  -上瘾入骨i
    2020-12-08 11:54

    Wow. I'm really surprise that no one actually got to the root of this, and instead, are just recommending workarounds.

    IdentityDbContext already contains a property:

    `public virtual IDbSet Users { get; set; }
    

    When you subclass IdentityDbContext to create your own application-specific context, you must specify what class satisfies the TUser generic. The default is:

    public ApplicationDbContext : IdentityDbContext
    

    Which then means that you functionally have a property already via inheritance in the form of:

    public IDbSet Users { get; set; }
    

    If you then add another property to your application-specific context such as:

    public DbSet ApplicationUsers { get; set; }
    

    You now have the same entity tracked by two DbSets, and you get that error. The solution? Simply don't add your own DbSet for ApplicationUser. There's no need to rename or override anything.

提交回复
热议问题