This can be used to avoid Error : PK cannot be modified :
"The property '
MyPrimaryKey' is part of the object's key information and cannot be modified. "
we can use this query :
var item = _context.MyTableName.First(z => z.Name == "Ardi");
var newItem = (MyTableName)_context.Entry(item).GetDatabaseValues().ToObject();
newItem.MyPrimaryKey = "Generated_" + DateTime.Now.ToString();
_context.SaveChanges();
No comments:
Post a Comment