我想用FK删除实体。这是我的代码:
var db = new DeresyDBEntities();
var item=db.Items.Where(p => p.ID == ItemId).SingleOrDefault();
if(item!=null)
{
foreach (var tag in db.ItemsTags.Where(p => p.ItemId == ItemId))
db.ItemsTags.Remove(tag);
foreach (var comment in db.ItemsComments.Where(p => p.ItemId == ItemId))
db.ItemsComments.Remove(comment);
foreach (var rate in db.ItemsVotes.Where(p => p.ItemId == ItemId))
db.ItemsVotes.Remove(rate);
db.Items.Remove(item);
db.SaveChanges();
return true;
}
还有其他方法可以删除吗?