4

I am using generic entity framework repository pattern for my oracle database.

public int Add(TEntity entity)
{
      var addedEntity = _context.Entry(entity);
      addedEntity.State = EntityState.Added;
      return _context.SaveChanges();
}

Simply, how can I get my entity Id after that is inserted to database with generated id.

Edit: I am using oracle 11g. So there is no 'identity' keyword. I created sequences for getting max ref and trigger it before inserting. So, the entity which is I send to EF not updating after SaveChanges();

Thanks...

Amit Joshi
  • 14,103
  • 20
  • 72
  • 131
cpzz
  • 55
  • 8

1 Answers1

1

For your identity-Column you have to set the property <storeGeneratedPattern> to <Identity> in the EF Model-Browser.

  1. Go to your entity in the Model Browser

    enter image description here

  2. Set property

    enter image description here

This will get the current, new value for your ID-Column after your identity has been saved.

Works for me with ORACLE, EF-Framework 6

Mr Lister
  • 44,061
  • 15
  • 107
  • 146
Karl
  • 2,971
  • 3
  • 19
  • 24