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.
精彩评论