Auto generated ID when inserting into table using EF

Auto generated ID when inserting into table using EF

Postby 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"
jlundstocholm
 
Posts: 1
Joined: Tue 09 Nov 2010 09:11
Location: Copenhagen, Denmark

Postby 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.
bolek75
 
Posts: 16
Joined: Mon 10 May 2010 08:58

Re: Auto generated ID when inserting into table using EF

Postby 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
rednose84
 
Posts: 9
Joined: Wed 10 Nov 2010 08:07

Postby Shalex » Wed 10 Nov 2010 17:47

Please refer to this thread and tell us if this helps.
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle