C# – Entity Framework Mapping Oddity – member names cannot be the same as their enclosing type

asp.netc++entity-framework

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.

Best Solution

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