I need to recreate a database with exactly the same values it has been originally created. So I need to add records with a pre-defined PK value. In this case, the PK is Identity in the database and when I try to define it's value, it is simply ignored, getting its value from the identity. No error is raised but the PK value that I supply is ignored.
example:
Category category = new Category()
{
CategoryID=1,
CategoryName="Beverages",
Description="Soft drinks, coffees, teas, beers, and ales"
};
ctx.Categories.Add(category);
ctx.SaveChanges();
Notes:
- I'm using POCO, code first, so, I don´t have an EDMX Model to configure.
- I don´t want to use
ctx.Database.ExecuteSqlCommand()
. I wish to maintain an Database agnostic approach.