How to retrieve the value of the primary key (@@IDENTITY) after a Linq insert ?

  • Thread starter Thread starter Gilbert Tordeur
  • Start date Start date
G

Gilbert Tordeur

Hello.

I work with a SQL table whose primary key is an automatic counter. When I
insert a new record with a stored procedure I can retrieve the value of its
primary key by looking at @@IDENTITY.

But if I use Linq and no stored procedure to insert a record, how can I get
this information ?

Thank you,
Gilbert
 
Did you check the object property after submit - the one that matches the id
column?
 
Miha,

No but you're right, the new value is stored in it. With stored procedure
(and no Linq) we needed a special action to retrieve it so I did not imagine
it was automatically done.

Thank you,
Gilbert

Miha Markic said:
Did you check the object property after submit - the one that matches the
id column?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Gilbert Tordeur said:
Hello.

I work with a SQL table whose primary key is an automatic counter. When I
insert a new record with a stored procedure I can retrieve the value of
its primary key by looking at @@IDENTITY.

But if I use Linq and no stored procedure to insert a record, how can I
get this information ?

Thank you,
Gilbert
 
Back
Top