del ara
شنبه 07 آبان 1390, 16:00 عصر
در یک جدول که به جداول دیگری ارتباط دارد میخواهم چند سطر را حذف کنم ، طوری که در همه جدول ها حذف شود . راه حل چیست؟ مشکل کد زیر ؟
publicvoid Del()
{
ShopDemoEntities shop = newShopDemoEntities();
Products pr = (Products)dgP.SelectedItem asProducts;
Orders or =newOrders();
Store st=newStore();
var query2 = (from q2 in shop.Store
where q2.ProductID == st.ProductID
select q2).SingleOrDefault();
shop.Store.DeleteObject(query2);
var query1 = (from q1 in shop.Orders
where q1.ProductID == or.ProductID
select q1).SingleOrDefault();
shop.Orders.DeleteObject(query1);
var query = (from q in shop.Products
where q.ProductID == pr.ProductID
select q).Single();
shop.Products.DeleteObject(query);
shop.SaveChanges();
}
}
publicvoid Del()
{
ShopDemoEntities shop = newShopDemoEntities();
Products pr = (Products)dgP.SelectedItem asProducts;
Orders or =newOrders();
Store st=newStore();
var query2 = (from q2 in shop.Store
where q2.ProductID == st.ProductID
select q2).SingleOrDefault();
shop.Store.DeleteObject(query2);
var query1 = (from q1 in shop.Orders
where q1.ProductID == or.ProductID
select q1).SingleOrDefault();
shop.Orders.DeleteObject(query1);
var query = (from q in shop.Products
where q.ProductID == pr.ProductID
select q).Single();
shop.Products.DeleteObject(query);
shop.SaveChanges();
}
}