Quick info:
- Using EF 4.1 Code First.
- Using POCO classes with no attribute decoration.
- Using fluent configuration in EntityTypeConfiguration<> classes to map POCO to database.
- Following DDD pattern, using generic repositories, aggregate roots, specification, etc.
Problem:
For entities with the primary key set as identity, DatabaseGeneratedOption.Identity should work fine.
However, in our current schema there is an "interesting" way to create primary keys. A stored procedure is called that create the "next" unique key to use (same sproc is called for several different tables to ensure a unique key across all of them). This was from a legacy structure that I'm not going to get into in this post, but I need to be able to implement it.
I am setting the map to DatabaseGeneratedOption.None. What is the best approach to handling the retrieval of the new id right before inserting a record? Is there an event I can handle on the DbContext?
Thanks!