i use Entity Framework 5.0 by "Model First". In 4.x there is a bug: the designer can't handle primary column guid with identy and defaultValue: "newid()" (source: http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/)
Is it still not possible to use this in EF5? What is the problem to transform c# guid to sql "uniqueid" ?
This worked for me doing database-first, but may help you after you've created your database -
You can update the table and set the default value as newid()
using Server Management Studio (not through EF).
Then in the EF model, update the StoreGeneratedPattern
from none
to Identity
.
2013 edit: For completeness, in EF 5.0 Codefirst, you can specify the following data annotation:
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public Guid TableIdColumn { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With