错误:不支持每种类型的多个对象集 [英] Error: Multiple object sets per type are not supported

查看:885
本文介绍了错误:不支持每种类型的多个对象集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是错误的详细信息:

Here is details of the error:


运行所选代码生成器时出错:'无法
'Models.ApplicationUser'的元数据。不支持每个类型的多个对象集
。对象设置'ApplicationUsers'和
'Users'都可以包含类型'Models.ApplicationUser'的实例。

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在MVC项目中架起视图的同时,我得到了同样的错误,如果我尝试scafford控制器。我在SO上看到一些这样的错误,但似乎这些不适用于我的情况。

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.

这是我的DbContext。它只是默认的MVC项目,还有更少的DbSets。我没有任何适用于ApplicationUsers或用户的DbSet或任何类似于我的上下文或任何项目中的任何内容。但是为什么我得到这个错误?

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

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

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

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

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?

环境:MVC5,EF6代码首先, VS2013 Ultimate,C#。

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

推荐答案

我一直面临同样的问题。

i have been facing same issue.

当我试图让我的代码中的所有应用程序用户,它自动创建以下属性ApplicationDbContext类:

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

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

请删除此行,一切都会很好。

这篇关于错误:不支持每种类型的多个对象集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆