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();
}
After performing the insert look at the
product.Idproperty (or whatever your id property is called). It will be updated by EF with the value assigned by the database.