public bool UpdateValues(String impR, String actR, String proR, String impV, String magV)
{
bool IsInserted = false;
try
{
MatrixValues c = cecbContext.MatrixValues.First(i => i.actv_reference == actR); // primary key
c = cecbContext.MatrixValues.First(i => i.impt_reference == impR); // primary key
c = cecbContext.MatrixValues.First(i => i.proj_reference == proR); // primary key
c.mtrxV_importance = double.Parse(impV); // updated value
c.mtrxV_magnitude = double.Parse(magV); // updated value
cecbContext.SaveChanges(); // getting an error here!!!
IsInserted = true;
}
catch (Exception)
{
IsInserted = false;
}
return IsInserted;
}
实体框架的更新语句试图更新细节导致错误
错误时,我得到一个错误是PRIMARY KEY约束“PK_MatrixValues”的
冲突。无法在对象'dbo.MatrixValues'中插入重复键。
你能告诉我如何更新价值观,我不想更新主键,我想更新只有两个值的字段 – Gayashan 2013-04-06 05:57:33