如何将以下内容转换为LINQ
- EF
select Name
from TableA as TableAOuter
group by TableAOuter.Name, TableAOuter.Id
having(
select count(TableAInner.Id)
from TableA as TableAInner
where TAbleAInner.Reference=TableAOuter.Id) = 0
);
答案 0 :(得分:2)
对我来说,这看起来像是:
var query = from row in tableOuter
group row by new { row.Name, row.Id } into g
where !tableInner.Any(inner => inner.Reference == g.Key.Id)
select g.Key.Name;
虽然我很想在分组之前执行过滤 - 此时你可以只对行名称进行分组:
var query = from row in tableOuter
where !tableInner.Any(row => inner.Reference == row.Id)
group row.Name by new { row.Name, row.Id };
我认为应该做同样的事情,对吗?