im using poco code first . how do i get the last insert after savechanges() ?
thanks
var newProduct = db.Product.Add(model);
db.SaveChanges();
var productId = model.Id;
It automatically adds it to the object you are saving
I resolve that problem in such way:
with Max() - you can get last id from table
db.Products.Add(product);
db.SaveChanges();
int lastProductId = db.Products.Max(item => item.ProductId);
ProductId is Key() and increment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With