ASP.NET Identity - Multiple object sets per type are not supported

后端 未结 4 634
栀梦
栀梦 2020-11-27 17:46

I got an error using ASP.NET Identity in my app.

Multiple object sets per type are not supported. The object sets \'Identity Users\' and \'Users\'

相关标签:
4条回答
  • 2020-11-27 17:53

    review this file "ApplicationDbContext.cs", remove the line, generated automatically by scaffold last, should be like this:

    public System.Data.Entity.DbSet<Manager.Models.ApplicationUser> IdentityUsers { get; set; }
    
    0 讨论(0)
  • 2020-11-27 18:04

    You do have two DbSets` of the same type.

    IdentityDbContext<T> itself contains Users property declared as:

    public DbSet<T> Users { get; set; }
    

    You're declaring second one in your class.

    0 讨论(0)
  • 2020-11-27 18:08

    Comment the new generated Dbset from identity model class like below

    // public System.Data.Entity.DbSet<SurveyTool.Models.ApplicationUser> ApplicationUsers { get; set; }
    
    0 讨论(0)
  • 2020-11-27 18:11

    This issue can arise from using scaffolding to create a View. You probably did something like this: View > Add > New Scaffold Item... > MVC 5 View > [Model class: ApplicationUser].

    The scaffolding wizard added a new line of code in your ApplicationDbContext class.

    public System.Data.Entity.DbSet<RecommendationPlatform.Models.ApplicationUser> IdentityUsers { get; set; }
    

    Now you have two DbSet properties of the same type which not only causes an exeptions to be thrown in the FindAsync() method but also when you try to use code-first migrations.

    Be very careful when using scaffolding or even better don't use it.

    0 讨论(0)
提交回复
热议问题