This is a migrated thread and some comments may be shown as answers.

Return new row identity

2 Answers 78 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard M
Top achievements
Rank 1
Richard M asked on 24 Nov 2010, 07:26 PM
I am trying to find an example for returning the ID of a newly created row using the EntityDiagrams model, instead of the ObjectScope method.  The "InsertOnSubmit" and "SubmitChanges()" properties are not available in the EntityDiagrams model.

2 Answers, 1 is accepted

Sort by
0
Richard M
Top achievements
Rank 1
answered on 24 Nov 2010, 07:48 PM
Ok, I figured out how to do this:

(Here's my table)
New table "TestTable"
UID (PK, int),
FieldName (varchar(20))


// Create a new connection:
MyEntityDiagrams conn = new MyEntityDiagrams();

//Create a new instance of the table:
TestTable myTable = new TestTable();

// Add field values:
myTable.FieldName = "fieldname";

// Add the new record to TestTable:
conn.Add(myTable);
conn.SaveChanges();

//  Retrieve the ID for the row that was created
int ID = myTable.UID;
0
Alexander
Telerik team
answered on 25 Nov 2010, 03:34 PM
Hello Richard M,

Yes, this is the correct way to get the newly generated id value. Please let us know if you need further assistance.

All the best,
Alexander
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
LINQ (LINQ specific questions)
Asked by
Richard M
Top achievements
Rank 1
Answers by
Richard M
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or