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
  • 15,448
  • 21
  • 77
  • 141
cpzz
  • 55
  • 11

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
  • 45,515
  • 15
  • 108
  • 150
Karl
  • 3,099
  • 3
  • 22
  • 24