当前位置: 动力学知识库 > 问答 > 编程问答 >

Entity framework 3.5sp1 delete all in associated table?

问题描述:

What is the equivalent to:

DELETE * from ProductsCategories WHERE ProductID = 78

using entity framework 3.5sp1? Need to delete all categories that belongs to a product.

/M

网友答案:

I have used code similar to this to delete records.

var productCategories = from pc in context.ProductCatgories
     where pc.ProductID == 78;
foreach(var category in productCategories)
{
    context.DeleteObject(category);
}

context.SaveChanges();
分享给朋友:
您可能感兴趣的文章:
随机阅读: