Auto generated ID when inserting into table using EF

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
jlundstocholm
Posts: 1
Joined: Tue 09 Nov 2010 09:11
Location: Copenhagen, Denmark

Auto generated ID when inserting into table using EF

Post by jlundstocholm » Tue 09 Nov 2010 09:28

I am using dotConnect 5.7 to connect to our ORACLE database. We have a table with an auto-incremented ID column.

I add new rows to the table using code like

Code: Select all

using (var entities = new  MyEntityModel())
{
    entities.MyMessageTable.AddObject(message);
    insertResult = entities.SaveChanges();
}
I would like to get my hands on the ID that was created in the new row in the table.

How do I do this? There are various posts on this forum asking similar questions, but none that I can find that use the entity model approach described here.

Essentially, I am looking for equivalant tothis post on MSDN entitled

"How to acquire the ID of last row inserted using Entity Framework"

bolek75
Posts: 16
Joined: Mon 10 May 2010 08:58

Post by bolek75 » Tue 09 Nov 2010 10:09

We created sequences in combination with triggers in our Oracle database. Before inserting a new record the trigger fetches a autoincrement value from the sequence and sets the value in the autovalue column of the table.

rednose84
Posts: 9
Joined: Wed 10 Nov 2010 08:07
Contact:

Re: Auto generated ID when inserting into table using EF

Post by rednose84 » Wed 10 Nov 2010 08:28

jlundstocholm wrote:I am using dotConnect 5.7 to connect to our ORACLE database. We have a table with an auto-incremented ID column.

I add new rows to the table using code like

Code: Select all

using (var entities = new  MyEntityModel())
{
    entities.MyMessageTable.AddObject(message);
    insertResult = entities.SaveChanges();
}
I would like to get my hands on the ID that was created in the new row in the table.

How do I do this? There are various posts on this forum asking similar questions, but none that I can find that use the entity model approach described here.

Essentially, I am looking for equivalant tothis post on MSDN entitled

"How to acquire the ID of last row inserted using Entity Framework"
Hy,

you have to set the StoredGeneratedPattern attribute in the Store part of the model.

After you saveAllChanges() your Model now should be the new one.
kind regards

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 10 Nov 2010 17:47

Please refer to this thread and tell us if this helps.

Post Reply