Get Identity column value

4 posts, 0 answers
    FISCAL avatar
    91 posts
    Member since:
    May 2010

    Posted 20 May 2010 Link to this post


    Is it possible to get the Identity column value once the record is inserted into the table successfully?


    M G
  2. Serge
    Serge avatar
    375 posts

    Posted 21 May 2010 Link to this post

    Hi M G,

    After you call scope.Transaction.Commit() (or .SaveChanges() in case you are using the new context approach) the identity column values are automatically populated with the new values. You can directly access them.
    Hope this helps.

    All the best,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Gaurav
    Gaurav avatar
    10 posts
    Member since:
    Feb 2012

    Posted 21 Mar 2012 Link to this post

    i am not using transaction for adding new enitity.
    i am using ria service for communication.
    after i add new object to entity through entitymodel new value of identity column not populated in that new object.

    is there any settings we need to do for that ????

    please help me
  4. PetarP
    PetarP avatar
    754 posts

    Posted 23 Mar 2012 Link to this post

    Hello Gaurav,

     No there shouldn't be any additional steps you need to do. Can you please look into the generated sql after you call context.SaveChanges and check if you get an select scope_identity() statement generated at the end of your insert query? If you are having that indeed appended can you please mark your primary key with the [Key] attribute inside your model.

    Kind regards,
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Back to Top