Clay Smith
Clay Smith

Reputation: 1079

Why does Entity Framework insist on renaming columns?

Step 1: import code first from existing database. Existing database has a table with the same name as column.

Step 2: in this scenario, Entity Framework sticks a "1" in front of column name in code.

Step 3: when I try to rename it "by getting rid of 1 in front", I get error

member names cannot be the same as their enclosing type

Why is this limitation on EF and is there a solution that doesn't ruin the database in future migrations (by having that column renamed)?

Being forced to use Column1 just seems really terrible and arbitrary.

Thanks.

Upvotes: 0

Views: 417

Answers (1)

undefined
undefined

Reputation: 34309

As pointed out by @shf301 you cant have a property named the same as the class its in, this is a .NET restriction.

However you can name your column anything else and then tell EF to point to your specific column in the database

eg:

[Column("MyColumn")] // "MyColumn" will be what EF expects in the db
public int FlyingMonkies {get;set;}

Upvotes: 1

Related Questions