Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
objectContext.Catalog.AddObject(catalog);

            return catalog.CatalogId;



Above code snippet is written in Repository layer and adds catalog object. I want to return some integer value back to the calling function which is in Business layer. But i want to do it without calling:
objectContext.SaveChanges();


catalog.CatalogId is primary key in the table which is an identity field and set to auto increment.
Posted

1 solution

Hi,

Your entity id, in your case "CatalogId" will have right value after inserting the entity and you need to call SaveChanges() method before you want to use it.
 
Share this answer
 
Comments
Peeyush Pachaori 5-Oct-12 5:00am    
This was the question - How to get primay key id without SaveChanges().
Martin Arapovic 5-Oct-12 6:19am    
Yes it is and I wrote that you need to call SaveChanges which means it can't be done without saving changes. As I know, object is inserted when SaveChanges method is executed, not before!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900