实体框架映射怪异 - 成员名称不能与它们的封闭类型 [英] Entity Framework Mapping Oddity - member names cannot be the same as their enclosing type
问题描述
我从一个数据库中创建的实体模型,并得到一个错误成员名称不能与它们的封闭类型。这意味着有一个属性相同的名称作为类。
I have created an Entity Model from a DB, and getting an error "member names cannot be the same as their enclosing type". Which means there is a Property the same name as the Class.
所以,错误的是这里
/// <summary>
/// There are no comments for Employee in the schema.
/// </summary>
[global::System.ComponentModel.BrowsableAttribute(false)]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public global::System.Data.Objects.DataClasses.EntityReference<Employee> EmployeeReference
{
get
{
return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Employee>("HumanResourceModel.FK_EmployeeReferenceMapping_Employee", "Employee");
}
set
{
if ((value != null))
{
((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference<Employee>("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
{
我可以通过重命名属性的名称(但是这将导致在未来的问题负载)修复这个错误,但是这是怎么从已创建code固定的吗?我改名为外键映射,但没有奏效。
I can "fix" this error by renaming the name of the Property (but this will cause loads of issues in the future) , but how is this fixed from the created code? I renamed the Foreign Key to Mapping but that didn't work.
任何想法?
干杯Sarkie。
推荐答案
想通了
<一个href=\"http://stackoverflow.com/questions/526530/entity-framework-loading-many-to-one-entity\">http://stackoverflow.com/questions/526530/entity-framework-loading-many-to-one-entity
由于它附加参考到多对一
Because it appends Reference onto a many to one
Employee.Load()
EmployeeReference.Load()
Employee.Load() EmployeeReference.Load()
,因为我有一个表EmployeeReference它在它的屁股死了!
and since I have a table EmployeeReference it died on its arse!
FIX =重命名employeeReferenceTable
Fix= rename the employeeReferenceTable
这篇关于实体框架映射怪异 - 成员名称不能与它们的封闭类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!