开发者

Returning the PK during a linq to sql insert

I want to retu开发者_Python百科rn the PK ID when I insert a new user via linq to sql.

how can I do this? i.e. is there anything built in or do I have to do 2 queries?


You don't have to do anything. Just check the PK field on the object you used to create it after you've done a SubmitChanges(). LINQ to SQL autopopulates it.


If you have a DB-generated ID field then it will be enough to set the Auto Generated Value property to True and the AutoSync property to OnInsert for this field in the model designer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜