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

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
 
M

Miha Markic

Did you check the object property after submit - the one that matches the id
column?
 
G

Gilbert Tordeur

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top