Click here to Skip to main content
11,927,156 members (55,322 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# LINQ C#4.0
            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:

catalog.CatalogId is primary key in the table which is an identity field and set to auto increment.
Posted 4-Oct-12 22:17pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100