Linq to Sql:插入后我可以返回Identity_Scope吗?

Jer*_*emy 4 identity-column linq-to-sql

在使用linq to sql进行插入后,如果我的表有标识列,我可以获取Identity_scope值吗?

CMS*_*CMS 6

Linq to SQL为您完成了工作,它在SubmitChanges调用方法之后可用的标识值.

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

entity.Id;
Run Code Online (Sandbox Code Playgroud)