Microsoft's Language Integrated Query is no doubt one of the most thrilling data access capability I cherish. This is just because of the flexibility you have in writing your queries within your code.
The power of LINQ is not limited to the data access as in (LINQ to SQL). LINQ can be used to query the active directory, XML, SharePoint lists etc.
Today I will like to discuss how to return @@IDENTITY or SCOPE_IDENTITY() in LINQ. The simple answer is to read the Id value you require immediately after submitting your changes.
e.g.
DataContext db = new ClassesDataContext();
PATIENT_DETAIL p = new PATIENT_DETAIL();
p.Address1 = txtAddress1.Text;
p.Address2 = txtAddress2.Text;
p.Address3 = txtAddress3.Text;
p.Address4 = txtAddress4.Text;
db.PATIENT_DETAILs.InsertOnSubmit(p);
db.SubmitChanges();
int myId = p.PASNumber; // This returns the Id generated by the database (where PASNumber represents the Primary key to be returned.)
The power of LINQ is not limited to the data access as in (LINQ to SQL). LINQ can be used to query the active directory, XML, SharePoint lists etc.
Today I will like to discuss how to return @@IDENTITY or SCOPE_IDENTITY() in LINQ. The simple answer is to read the Id value you require immediately after submitting your changes.
e.g.
DataContext db = new ClassesDataContext();
PATIENT_DETAIL p = new PATIENT_DETAIL();
p.Address1 = txtAddress1.Text;
p.Address2 = txtAddress2.Text;
p.Address3 = txtAddress3.Text;
p.Address4 = txtAddress4.Text;
db.PATIENT_DETAILs.InsertOnSubmit(p);
db.SubmitChanges();
int myId = p.PASNumber; // This returns the Id generated by the database (where PASNumber represents the Primary key to be returned.)
QED
Comments
thanks!
Dim p As New PATIENT_DETAIL()
p.Address1 = txtAddress1.Text
p.Address2 = txtAddress2.Text
p.Address3 = txtAddress3.Text
p.Address4 = txtAddress4.Text
db.PATIENT_DETAILs.InsertOnSubmit(p)
db.SubmitChanges()
Dim myId As Integer = p.PASNumber
How can I return the scope_identity() then?
J
But Sharepoint standard packaged misses that control
I am looking for available solutions on market
I came across
http://sharepointfields.com
Does anybody has experiece using it?