Obtain the Identity of a New Row Using LINQ
●
Permalink
●
suggest edit
It’s actually pretty easy and user friendly to obtain the value of the identity column using LINQ. After you create your object and insert it on submit, you can call the identity column’s property on your object. For instance:
1
2
3
4
Dim db As New BlogDataContext()
db.BlogPosts.InsertOnSubmit(MyPost)
db.SubmitChanges()
Dim IdentityValue As Integer \= MyPost.PostID
In this example, the IdentityValue
variable would be assigned to the PostID
of the post that was just submitted.