0

SO I read here In Entity Framework, getting the value of an identity column after inserting that if you do this :

var entity = new Entity_Table { item1 = val1, item2 = val2 }; 
dbcontext.Entity_Tables.Add(entity); 
dbcontext.SaveChanges(); 
int newPK = entity.ID;

You can get the identity of the row you inserted. However, entity.ID does not appear in my sceneario.

My sceneario: 
1. I build the database with a sql script
2. Then I read it as a edmx file 
3. Then I ADO.NET DbContext Generator which creates NameOfMyEntity.Context.tt and NameOfMyEntity.tt 

I can insert, update and delete successfully. But I cant see entity.ID. I receive no errors on runtime or compile time!@ Please help!

Community
  • 1
  • 1
hidden
  • 3,216
  • 8
  • 47
  • 69

1 Answers1

0

It is no longer Entity.Id is just Entity.Whateveryounameyourprimarykey

hidden
  • 3,216
  • 8
  • 47
  • 69
  • correct, in the article you read ID happened to be what they named their key. I highly recommend others don't use "ID" instead CustomerId, OrderId, etc even on the customer/order table itself. – Adam Tuliper Apr 02 '12 at 18:55