.net - Entity Framework 逻辑实体错误

标签 .net entity-framework entity-framework-4

我想在模型中包含一个Person实体。没有相应的表格,也没有区分符。我只是希望将其作为其他实体共享的通用基类(我想定义具有通用功能的public partial class Person

因此,例如,我想要:

// this class has no corresponding table in the DB
public partial abstract class Person 
{
    public int Id {get; set;}
    public string FirstName {get; set;}
    public string LastName {get; set;}

    public string DisplayName { get { return string.Format("{0}, {1}", LastName, FirstName); } }
}

// this corresponds to dbo.Users
public partial class User : Person
{

}

// this corresponds to dbo.Contacts
public partial class Contact : Person 
{
}


因此,我创建了一个抽象实体Person,将其设置为User和Contact实体的基类,然后添加我的属性,并为dbo.Users和dbo.Contacts设置了PK Id,FirstName和LastName属性的映射。

我得到错误:

 3032: Problem in mapping fragments starting at lines 2109
..... are being mapped to the same rows in table .... Mapping conditions can be used to distinguish the rows that these types are mapped to.


我该如何工作?

最佳答案

您必须在EDMX文件中定义Person实体,并从EDMX中的User继承ContactPersonPerson中定义的属性均不能出现在继承的实体中。然后转到映射详细信息并将继承的实体映射到相应的表。

请注意,主键现在必须对所有人都是唯一的-不仅在派生实体中。

关于.net - Entity Framework 逻辑实体错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6273498/

相关文章:

.net - MVC 4 项目中缺少 'DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246'

entity-framework - MVC3和EF数据优先: what are the best practices?

c# - Entity Framework 6.1 和使用新关键字隐藏成员

c# - 枚举关联时如何改善糟糕的 EF4 性能?

c# - 使用长时间运行的后台使用者任务时 Task.Factory.StartNew 中的静默异常?

.net - 从packages.config 迁移到PackageReferences 导致无法加载文件或程序集 "..."或其依赖项之一。访问被拒绝

c# - 更新异常 : Operation is not valid due to the current state of the object when using Entity Framework and Oracle

entity-framework - 我可以强制使用 Entity Framework 的多重性/关联吗?

c# - ASP.net MVC 2.0 使用相同的表单进行添加和编辑

c# - 如何在 C# 中使用代理访问 Web 服务