我得到「該對象無法刪除,因爲它沒有在ObjectStateManager中找到」。同時刪除對象。實體框架刪除對象問題
這裏是代碼;
//first i am filling listview control.
private void Form1_Load(object sender, EventArgs e)
{
FirebirdEntity asa = new FirebirdEntity();
ObjectQuery<NEW_TABLE> sorgu = asa.NEW_TABLE;
foreach (var item in sorgu)
{
ListViewItem list = new ListViewItem();
list.Text = item.AD;
list.SubItems.Add(item.SOYAD);
list.Tag = item;
listView1.Items.Add(list);
}
//than getting New_table entity from listview's tag property.
private void button3_Click(object sender, EventArgs e)
{
using (FirebirdEntity arama = new FirebirdEntity())
{
NEW_TABLE del = (NEW_TABLE)listView1.SelectedItems[0].Tag;
arama.DeleteObject(del);
arama.SaveChanges();
}}
我現在得到這個錯誤;一個實體對象不能被IEntityChangeTracker的多個實例引用。 – 2009-08-01 17:44:27
您需要將它從提供給實體的ObjectContext中分離出來。以對象作爲參數調用ObjectContext.Detach。 – jason 2009-08-01 17:53:45