Saturday, November 21, 2009

Acquire the ID of last inserted row using Entity Framework

Acquiring the ID of last inserted row (Primary and auto increment column) using Entity Framework is as follows:

 
Entities oEntities = new Entities();
tblSample ts = new tblSample();
ts.Description = "some Description Here!!!";
oEntities.InsertToSample(ts);
oEntities.SaveChanges();

lblMessage.Text = ts.SampleID;

3 comments: