I am using below code to get new inserted ID in auto identity column from database.
using (TestEntities entities = new TestEntities())
{
T2 t2 = new T2();
t2.Value = "some value";
entities.AddToT2(t2);
entities.SaveChanges();
Console.WriteLine(t2.ID);
}
It’s working fine when I connect my application with MS Sql, but if I connect with Mysql, it always returns 0 (zero).
Is there any other way to get last inserted ID using Entity Framework?
Thanks…
Finally I got soln. The table I was inserting row had only one column – ‘ID’ with auto identity = true. When I add one more nullable column with any name in table It’s start working with my sql too!!! I think the problem is in my sql connector and not in entity framework.
Thanks 🙂