Entity Framework Reference

asp.net c# entity-framework

Question

I'm attempting to configure SQL Server 2008 with Entity Framework. For the keys on my tables, I use Guids. Is it possible to set it up such that the database generates the keys on its own? I tried making the column's default value "(newid())" and setting "RowGuid" to true. In any case, I still need to provide the mapped class a Guid on the C# side. Any thoughts?

1
10
12/1/2008 9:20:49 PM

Accepted Answer

still not:

17.4.Can I use a server-generated guid as my entity key?

Unfortunately, in v1 of the EF this is not supported. While it is possible with SQL Server to have a column of type “uniqueidentifier” and to set it’s default value to be “newid()”, with SQL Server 2000 there’s no good way to extract the value that the server generated at the time you do the insert. This can be done on more recent versions of SQL Server, though, so the intent is that we should find a clean way to special case this support in future versions of the EF so it can be supported on those databases that allow it and not on others. For now, the work around is to generate the guid on the client (ideally in the constructor of your object) rather than on the server.

6
12/1/2008 9:54:49 PM

Popular Answer

Personally, I believe that anybody utilizing EF would be prepared to forgo support for SQL Server 2000 in order to get the functionality they want. Because they have to maintain compatibility with SQL Server 2000, it feels like any halfway non-trivial thing I need to perform with EF is not supported.

When will this madness end?



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow