Home > C# | Entity Framework > Add ID value for non-auto-increament field under Entity Framework

Add ID value for non-auto-increament field under Entity Framework

May 29, 2014 Comments Off on Add ID value for non-auto-increament field under Entity Framework

If you use an “ID” field in your entity, & this “ID” field is not auto-increament, Entity Framework will fail when generate insert sql.

Solve:

Add a DatabaseGeneratedAttribute to this “ID” field, with DatabaseGeneratedOption.None option, like this:

Successfully solved under Entity Framework 4-6.

Tags: C# EntityFramework