我在调用提交更改时遇到linq2sql数据连接器无法更新数据对象的问题
我在按钮点击事件上有这个代码,虽然它失败了,因为它将Index设置为1(存在于db中) - 而不是我在对象中指定的3
我开始得到DuplicateKetException未处理,如果我查看详细信息,我看到对象中有旧数据 (Index = 1,Model = blah,Service = blah)
我做错了什么,是否需要刷新一些缓存???
public void button_Add_Click(object sender, RoutedEventArgs e)
{
using (DataClasses1DataContext dc = new DataClasses1DataContext());
{
Equipment equip = new Equipment
{
Index = 3,
Model = “ABCD1234",
Service = DateTime.Now
};
//Add the new object to the equip collection.
dc.Equipments.InsertOnSubmit(equip);
//Submit the change to the database.
dc.SubmitChanges();
}
//catch (Exception e)
{
//Console.WriteLine(e);
dc.SubmitChanges();
}
}