0

我正在使用 MVC3、EF4.1、C#。

我有这个 SQL 代码,我想将其转换为 LINQ,但我正在努力掌握正确的 LINQ,因此我正在向您的专家 LINQ 专家寻求帮助。

从触发器中获取的删除 SQL 是:

DELETE FROM Feature 
WHERE NOT EXISTS  
(
SELECT    
LU1 AS LUID 
FROM dbo.CLASS WHERE SectionId = Feature.SectionId AND LU1 = Feature.StdLibraryItemId
UNION 
SELECT    
LU2 AS LUID 
FROM dbo.CLASS WHERE SectionId = Feature.SectionId AND LU2 = Feature.StdLibraryItemId
)

非常感谢提前。

4

1 回答 1

1

它在 EF 中看起来像这样(假设你的 DbContext 是db):

var featuresToRemove = db.Feature.Where(f => !db.Class.Any(c => c.SectionID == f.SectionID && (c.LU1 == f.StdLibraryItemID || c.LU2 == f.StdLibraryItemID ))
foreach (var feature in featuresToRemove)
{
    db.Feature.Remove(feature);
}
于 2013-09-19T23:45:56.507 回答