Reputation: 272
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.
So the error is here
/// <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);
}
}
}
which is part of
[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
{
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.
Any ideas?
Cheers Sarkie.
Upvotes: 4
Views: 6880
Reputation: 272
Figured it out
Entity Framework: Loading Many to One entity
Because it appends Reference onto a many to one
Employee.Load() EmployeeReference.Load()
and since I have a table EmployeeReference it died on its arse!
Fix= rename the employeeReferenceTable
Upvotes: 4
Reputation: 17010
So the class in question is ...
public class Employee
{
public object Employee { get; set; }
}
I realize this is an entity framework model and you are not specifying it in code, but this is essentially what you have created, right?
If so, I see no way other than renaming the property or the object, due to the way EF works. It may not be the friendliest system in the world, but the rules are necessary with the way EF was coded.
I am sure any renaming issue you have with changing one name or another can be overcome. If not, consider another data access methdology.
Upvotes: 3