Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ C#4.0
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 4-Oct-12 22:17pm

1 solution

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

Solution 1

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.
  Permalink  
Comments
Peeyush Pachaori at 5-Oct-12 5:00am
   
This was the question - How to get primay key id without SaveChanges().
Martin Arapovic at 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
0 DamithSL 245
1 Sergey Alexandrovich Kryukov 217
2 OriginalGriff 200
3 Peter Leow 160
4 Afzaal Ahmad Zeeshan 85
0 OriginalGriff 7,380
1 DamithSL 5,359
2 Sergey Alexandrovich Kryukov 4,944
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
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