Click here to Skip to main content
12,296,779 members (56,806 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# 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 21: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 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.160525.2 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2016
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