Bumble Blee
Bumble Blee

Reputation: 79

How to get identity from database using Linq?

I am new to Linq-to-SQL.

I want to retrieve the identity value from Linq-to-SQL while using DBContext.SubmitChanges().

Upvotes: 0

Views: 416

Answers (2)

normanthesquid
normanthesquid

Reputation: 700

After you have called SubmitChanges() you can access the id field of your object to retrieve the ID.

Upvotes: 2

user194076
user194076

Reputation: 9027

It should automatically update your record. Something like this:

Customer cust = new Customer();
 cust.Company = "blah";
context.Customers.Add( cust );
context.SubmitChanges();
int NewPk = cust.Pk;

Upvotes: 3

Related Questions