Linq to Sql:插入后我可以返回标识范围吗?

时间:2009-11-13 04:59:48

标签: linq-to-sql identity-column

使用linq to sql进行插入后,如果我的表有标识列,是否可以获取Identity Scope值?

1 个答案:

答案 0 :(得分: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;