entity framework映射奇数 – 成员名称不能与其封闭类型相同
我已经从DB创建了一个实体模型,并且收到错误“成员名称不能与其封闭类型相同”。 这意味着有一个Property与Class同名。
所以错误在这里
/// /// There are no comments for Employee in the schema. /// [global::System.ComponentModel.BrowsableAttribute(false)] [global::System.Runtime.Serialization.DataMemberAttribute()] public global::System.Data.Objects.DataClasses.EntityReference EmployeeReference { get { return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference("HumanResourceModel.FK_EmployeeReferenceMapping_Employee", "Employee"); } set { if ((value != null)) { ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference("HumanResourceModel.FK_EmployeeReferenceMapping_Employee", "Employee", value); } } }
这是其中的一部分
[global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName="HumanResourceModel", Name="EmployeeReference")] [global::System.Runtime.Serialization.DataContractAttribute(IsReference=true)] [global::System.Serializable()] public partial class EmployeeReference : global::System.Data.Objects.DataClasses.EntityObject {
我可以通过重命名属性的名称来“修复”此错误(但这将导致将来出现大量问题),但是如何从创建的代码中修复此问题? 我将外键重命名为映射,但这不起作用。
有任何想法吗?
干杯萨基。
弄清楚了
entity framework:将多个实体加载到一个实体
因为它将引用附加到多对一
Employee.Load()EmployeeReference.Load()
因为我有一张桌子EmployeeReference就死了!
Fix =重命名employeeReferenceTable
所以这个课程是……
public class Employee { public object Employee { get; set; } }
我意识到这是一个entity framework模型,你没有在代码中指定它,但这基本上就是你创建的,对吧?
如果是这样,由于EF的工作方式,我认为除了重命名属性或对象之外别无他法。 它可能不是世界上最友好的系统,但规则对于EF编码的方式是必要的。
我确信您可以克服任何更改一个名称或更别名称的重命名问题。 如果没有,请考虑另一种数据访问方法。