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?
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.
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?