The category table in the database is defined as follows:
CategoryID - PK ,identity specification ON (only this column has identity)
Description
Title
I want to insert new data:
Category cat = new Category
{
Description = "xxx",
Title = "yyy",
};
if (cat.EntityState == EntityState.Detached)
{
Articlerctx.AddToCategories(cat);
}
return Articlerctx.SaveChanges();
I get an error:
You cannot insert an explicit value for the identity column in the Categories table if IDENTITY_INSERT is set to OFF.
But I do not insert CategoryID! I want it to get auto value!
asker source
share