Reputation: 26028
I am using Entity Framework 4.1 code first
. I have a product table that has an Id column that is an auto incremented column. When I add the the Product instance, how do I get this new id or the updated Product (returned with properties)?
My repository code:
MyContext db = new MyContext();
public void Insert(Product product)
{
db.Products.Add(product);
db.SaveChanges();
}
Upvotes: 4
Views: 4498
Reputation: 1038820
After performing the insert look at the product.Id
property (or whatever your id property is called). It will be updated by EF with the value assigned by the database.
Upvotes: 7