开发者

Linq to Sql: Can I return the Identity_Scope after an insert?

开发者 https://www.devze.com 2022-12-11 21:16 出处:网络
After I do an insert using linq to sql, can I get the Identity_scope value back if my table has an iden开发者_开发问答tity column?Linq to SQL does the job for you, the identity value it\'s available j

After I do an insert using linq to sql, can I get the Identity_scope value back if my table has an iden开发者_开发问答tity column?


Linq to SQL does the job for you, the identity value it's available just after the SubmitChanges method is called.

var entity = new Entity();
// ...
ctx.Entities.InsertOnSubmit(entity);
ctx.SubmitChanges();
// Here you can use the generated value of yout identity column

entity.Id;
0

精彩评论

暂无评论...
验证码 换一张
取 消