Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework appending '1' to property name when it matches entity name

I am using Entity Framework version 4.0 to create a model using the database first approach. In the database, there's a number of tables that contain columns named the same as their parent table.

So for example we have

  • table State with columns State and StateName
  • table Status with columns Status and Description

The issue is that when one of these tables is imported into the EF model, the property names that those columns get mapped to get a '1' appended to the end of them.

So I end up with

  • entity State with properties State1 and StateName
  • entity Status with properties Status1 and Description

When I attempt to remove the '1' at the end, I get a message saying "The name Status cannot be duplicated in this context. Please choose another name."

Is there a way for me to have my properties keep their names or is this a documented limitation in the framework?

like image 893
Vlad Tamas Avatar asked Oct 26 '15 14:10

Vlad Tamas


1 Answers

You can't have a member in your class which is named like your class is.

Example:

class Test
{
    // Invalid
    int Test;

    // Invalid
    public int Test {get; set; }

    // OK
    int Test1; 
}
like image 64
Aizaz Ahmed Avatar answered Sep 18 '22 11:09

Aizaz Ahmed