none
SCOPE_IDENTITY() with LINQ to SQL? RRS feed

  • Question

  • I've been using LINQ to SQL the past few weeks, and LOVE it!  I'm having an issue though.  Lets say I do this:

     _db.Clients.InsertOnSubmit(client);

    How can I retrieve the ID of the Client that was just inserted? I know
    SCOPE_IDENTITY() does that, but how can I use it?

    Thanks for your help!

    Brenda
    Tuesday, August 12, 2008 2:18 AM

Answers

  • L2S does that automatically for you.  The result of the SCOPE_IDENTITY is pushed back into your object.  You can simply access the ID property on the client object.

     

     

     

    Tuesday, August 12, 2008 2:30 AM
    Moderator

All replies

  • L2S does that automatically for you.  The result of the SCOPE_IDENTITY is pushed back into your object.  You can simply access the ID property on the client object.

     

     

     

    Tuesday, August 12, 2008 2:30 AM
    Moderator
  • WOW, that is AWESOME! Thanks!
    Tuesday, August 12, 2008 2:37 AM
  • Wonderful.... I am assuming that the newly generated id will be propagated to all child objects too..

     

     

    --Hari

     

    Tuesday, August 12, 2008 5:00 PM