views:

715

answers:

2

Hi Guys,

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.

+1  A: 

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.

Gregory A Beamer
Yeah apart from that is what EF created, but EmployeeReference. I can edit it manually, I was trying to figure out how it made the name, so I can edit it in the DB.
Sarkie
The best way to see what is going on is to Reflect the assemblies that create the autogened stuff. Reflector is now a RedGate tool, but it is still free. A pain? Sure, but you learn so much. :-)
Gregory A Beamer
A: 

Figured it out

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()

and since I have a table EmployeeReference it died on its arse!

Fix= rename the employeeReferenceTable

Sarkie