1

This was working with EF5 but there seems to be an issue with EF6.

We are trying to save a new row to a table using EF6. The primary key column is marked as an Identity value and we have an insert trigger on the table.

When we call db.saveChanges() it always tries to use 0 as the primary key column value.

If we insert a record through Toad it uses the trigger correctly. So the trigger is working.

If we change the trigger to check for 0 instead of null then it also works.

Has anybody else had this issue with EF6?

Thanks, Joe

  • In EF4 I always had to get the new primary key by selecting the sequence value from dual. Then any inserts used the correct primary key and this was now available for inserts into child tables. – kevinskio Aug 14 '15 at 15:18
  • @kevinsky, that is basically what his BI trigger likely does. – LSU.Net Aug 14 '15 at 15:26
  • What version of Oracle.Net are you using? – LSU.Net Aug 14 '15 at 15:27
  • 12.1.022 version of Oracle.Net – Joe Phillips Aug 14 '15 at 15:42
  • @LSU.Net Sure, triggers work great in Oracle but they don't return the value of the primary key that has been added. The trigger action is behind the scenes. I found it was easier to let EF drive the transaction by getting a primary key and inserting it as part of a record. – kevinskio Aug 14 '15 at 16:08
  • 1
    Are you using Database First/EDMX generation? If so, What is the StoreGeneratedPattern set to? – LSU.Net Aug 14 '15 at 16:19
  • Here are a couple of links on this issue. http://blog.aitgmbh.de/2014/06/02/patch-for-entity-framework-models-based-on-oracle-databases/ http://stackoverflow.com/questions/23661666/ef-5-with-oracle-edmx-storegeneratedpattern-identity-issue – LSU.Net Aug 14 '15 at 16:20

1 Answers1

0

With 12c it works fine

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Number { get; set; }
Toolkit
  • 10,779
  • 8
  • 59
  • 68