Entity Framework ValueGeneratedOnAdd with no requery

75 Views Asked by At

Say I have EntityFramework Core 2.1.14.

Say I have to integrate data into a legacy MySql database which was created by a self-taught.

Say also that one of the tables in this database has a surrogate key field that is generated on Add.

Say then that I want to use context.SaveChanges() to handle the Insert DML generation for me because I want to be lazy and because these tables are messy.

Say finally that I do not want Entity Framework to perform a follow-up query to retrieve this surrogate field; I don't care what it is. I just need it generated on insert.

How would one call context.SaveChanges() with an Added object having a property configured as .ValueGeneratedOnAdd() but also instruct Entity Framework to do nothing but generate my INSERT ? I don't want it to return the id.

0

There are 0 best solutions below