2

下面是错误的详细信息:错误:每个类型的多个对象集,不支持

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'.

我得到这个,而脚手架MVC项目中的视图。我得到了同样的错误,如果我尝试scafford控制器。我已经看到了一些这样的错误,但它似乎不适用于我的情况。

这是我的DbContext。它只是带有几个DbSets的默认MVC项目。我没有任何DbSet的ApplicationUsers或用户或类似的东西在我的上下文或项目中的任何地方。但是,为什么我得到这个错误?

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; }   
} 

这是我的List类。我怀疑这个错误与它有关。但为什么?

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; } 
} 

这是在所有实体中唯一引用ApplicationUser的地方。还有一个问题,有点偏离主题是“扩展IdentityDbContext而不是在应用程序中创建新的DbContext是不好的决定?

环境:MVC5,EF6 Code First,VS2013 Ultimate,C#。

+1

你用'DbContext'试过了吗?你有同样的错误吗? –

+0

嗨Inanikian,感谢您的评论。我不明白。由于ApplicationUser是从IdentityUser继承的,如果我将IdentityDbContext更改为DbContext,那么在应用程序中将会有数十个错误。我该怎么办? – lawphotog

+0

[VS 2013控制器脚手架失败的可能重复的应用程序用户模型(不支持多个对象集每个类型)](http://stackoverflow.com/questions/19888576/vs-2013-controller-scaffolding-fails-for-所述-applicationuser模型-多OBJ) –

回答

0

我觉得这是你回答

public class ApplicationUser : IdentityUser 
{ 
     public virtual ICollection<List> Lists{ get; set; } 
} 

你必须给用户类的ICollection的

0

我一直面临着同样的问题。

当我试图让所有应用程序用户在我的代码,它会自动创建下列财产中ApplicationDbContext类:

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

请删除此行,一切都会好起来的。

相关问题