我收到此错误:无法在具有唯一索引'in_name'的对象中插入重复的键行 可能是什么问题?
var ing = (from x in db.tblTable where x.ing_name == ing_name select x);
var ing1 = ing.First();
ing1.ing_name = ing1.ing_name + " (" + FormatC(ing_brand) + ")";
db.SaveChanges();
这是FormatC:
public static string FormatC(string str)
{
if (!string.IsNullOrEmpty(str))
return str.Substring(0, 1).ToUpper() + "" + str.Substring(1).ToLower();
else
return "";
}