Error: Multiple object sets per type are not supported

asp.net-identity asp.net-mvc c# entity-framework entity-framework-6

Question

Here is details of the error:

There was an error running the selected code generator: 'Unable to retrive metadata for 'Models.ApplicationUser'. Multiple object sets per type are not supported. The objects sets 'ApplicationUsers' and 'Users' can both contain instances of type 'Models.ApplicationUser'.

I am getting this while scaffolding a view in MVC project. I got the same error if i try to scafford a controller. I have seen a few of this error on SO but it seems those don't apply to my case.

Here is my DbContext. It is just the one comes with default MVC projects with few more DbSets. I don't have any DbSet for ApplicationUsers or Users or anything like that on my context or anywhere in the project. But why am i getting this error?

public class ApplicationUser : IdentityUser
{        
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {            
    }

    public virtual DbSet<ItemType> ItemTypes { get; set; }
    public virtual DbSet<Item> Items { get; set; }
    public virtual DbSet<Category> Categories { get; set; }
    public virtual DbSet<List> Lists { get; set; }
    public virtual DbSet<Level> Levels { get; set; }        
}

Here is my List class. I suspect this error has something to do with it. But why?

public class List
{
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }        
    public string UserId { get; set; }

    public virtual ICollection<Item> Items { get; set; }
    public virtual ApplicationUser User { get; set; }
}

This is the only place that has reference to ApplicationUser in all entities. One more question, a bit off topic is 'was it bad decision to extend IdentityDbContext rather than creating a new DbContext in the application?

Environment: MVC5, EF6 Code First, VS2013 Ultimate, C#.

1
2
5/1/2014 2:23:57 PM

Popular Answer

i have been facing same issue.

when i tried to get all Application users in my code, it automatically created following property in ApplicationDbContext class:

public System.Data.Entity.DbSet<Xxx.DataInputManagerWebUI.Models.ApplicationUser> ApplicationUsers { get; set; }

please remove this line and all will be fine.

1
7/29/2019 4:37:21 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow