I’m defining POCO’s, used with the Code First capabilities of Entity Framework 4.0.
But as my data comes from an external source, and I want to keep the identity column identical to that of the external source, I want to set the ID myself.
I’m setting the ID in my code before calling DbContext.Add() & context.SaveChanges(), but the ID values is ignored and set by the Auto Increment (AI) defined on the DB column.
The DB is mySQL and was auto generated by the EF.
Does anyone know how can I prevent the creation of the AI attribute on the ID column, or explicitly set the entity ID although the column is defined that way?
Edit: The answer I got from @flem works for me. But I need a slightly different scenario to work as well:
Is it possible to define the POCO in such a way, that when I set the value it would use it, and when I don’t, it would auto increment?
According to this mySQL forum answer mySQL is supposed to handle this scenario pretty well, but it seems that the Entity Framwork doesn’t…
Set Database generation to None.