Using natural keys with entity code first

Go To StackoverFlow.com

0

So, I'm using Entity Framework and need to now how set my own primary key.

Im using the [Key] data annotation but when I persist the entity that field is autogenerated even having that I previously set that property.

Any idea?

2012-04-05 19:00
by Erre Efe


3

I believe that in your [Key] Attribute you need to specify the DatabaseGeneratedOption as follows:

[Key, DatabaseGenerated(DataBaseGeneratedOption.None)]
2012-04-05 19:12
by mreyeros
Thanks buddy. Did not think about that - Erre Efe 2012-04-05 19:14
Ads