Reputation: 2562
Please help me understand this.
When I save a new object to the database (using Entity Framework), am I able to access the newly created ID (Identity column) value in the line(s) after I call db.SaveChanges()?
public Class TheObject
{
public int ID { get; set; }
public string FirstName { get; set; }
}
.....
TheObject MyObject = new TheObject();
MyObject.FirstName = "John";
db.TheObjects.Add(MyObject);
db.SaveChanges();
int MyNewID = MyObject.ID; //Am I able to access MyObject.ID here and have access to the value that was just created in the database?
Upvotes: 0
Views: 60
Reputation: 588
Yes you are but why not just run that code and test it yourself?
Upvotes: 1