0
我有一个存储“标签”像这样的表:LINQ到SQL - 删除多对多如果没有关系
ProductTags
TagID PK
Name nvarchar(50) [not null]
和M2M映射表是这样的:
ProductTagMap
ProductID PK
TagID PK
现在,让我们说我从一个产品删除标记的关系(或全部),像这样:
// get our Product we are working on...
Product product = dataContext.Products.Where(p > p.ProductID = 1);
// this remove the link between the product and its tags
dataContext.ProductTagMaps.DeleteAllOnSubmit(product.ProductTagMaps);
//*** If these product-specific Tag/s is/are no longer used ***/
//*** by any other Products I'd like to delete them ***/
//*** How can this be done here? ***/
dataContext.SubmitChanges();
如果这些标签(与特定产品相关)不再与我希望它们删除的任何产品相关。 如何在上面的代码中完成(请参阅评论)?