From: | JeffL |
To: | Rick Strahl |
What product are you guys talking about?
Let the database do it. EF takes care of creating the PK and automatically backlinking the child entities. If you create an order object, and attach child lineitems (via a List<LineItem> collection) EF will automatically fix up the PKs for you. That's one of hte reasons you want to use an ORM in the first place so you don't have to worry about key generation.
My old business object framework used to do exactly the same thing as wwBusiness, but it's simply better to let the database handle this sort of thing for you and then read back the generated new key if necessary.
+++ Rick ---
Rick - I'm now to the point with my MVC app using your MVC classes and and EF wrapper where I can add child records to a parent BO. Of course, every new parent and child record needs a unique PK assigned and during this testing and playing-around phase, the Id fields in each table are NOT set as AutoInc fields in SQL Server.
I know in your wwBusiness for FoxPro, you use a ww_id table and have a CreateNewId() method to pull new PKs before writing new records to the tables.
So, I'm curious to know if you have (or plan to) a way to "create new id" in the EF BO wrapper before calling Save(), or do you think it is a good practice to just let the Sql Server field be set as AutoInc for all tables.
In this case, I control the database so I can go either way. However, it's still something I'd like to understand from both angles (locally assigned vs. Db assigned).
Thanks.