KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a problem with Entity Framework in ASP.NET. I want to get the Id value whenever I add an object to database. How can I do this? According to Entity Framework the solution is: using (var context = new EntityContext()) { var customer = new Customer() { Name = "John" }; context.Customers.Add(customer); context.SaveChanges(); int id = customer.CustomerID; } This doesn't get the database table identity, but gets the assigned ID of the entity, if we delete a record from the table the seed identity will not match the entity ID.
Tags (comma-separated)
Save Edits
Cancel