Does the Entity Framework 4 support generators for id values like NHibernate? NHibernate has generator classes to help with this.
Asked
Active
Viewed 1,043 times
1 Answers
4
EF4 supports whatever the back-end server supports:
- IDENTITY columns or GUID columns with default values (newid(), newsequentialid()) in SQL Server
- Sequences in Oracle
- whatever other mechanism the target database might provide
EF4 itself doesn't have any built-in support for generators of any kind, as far as I know.
I'm not sure if making this the ORM's responsibility is a good idea, quite honestly. This should really be left to the backend store to handle, in my opinion.
However, you should have no trouble implementing your own custom ID generator in .NET code, and plug that into EF4, if you wish to do so.

Ian Nelson
- 57,123
- 20
- 76
- 103

marc_s
- 732,580
- 175
- 1,330
- 1,459
-
2I appreciate the information on the fact that EF4 doesn't support ID generators. However -1 for glossing over this deficiency with an uninformed opinion. In fact, client-side generation of IDs is the only way to effectively implement disconnected, distributed, and/or syncing systems. Having the datastore generate identifiers is often an unnecessary, and sometimes impossible, point of serialization. – joshperry Mar 11 '11 at 15:56
-
Agree with joshperry. Plus, server-side id generation makes it impossible to implement statements batching. With batching, massive inserts via ORM can be almost as fast as pure ADO.NET code. – Dmitry Arestov Feb 25 '14 at 05:01