开发者

LINQ Having Clause with inner select

How would the following be converted to LINQ-EF

select Name开发者_StackOverflow社区
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
);


To me, that looks like:

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;

Although I'd be tempted to perform the filtering before the grouping - at which point you can just group the row name:

var query = from row in tableOuter
            where !tableInner.Any(row => inner.Reference == row.Id)
            group row.Name by new { row.Name, row.Id };

I think that should do the same thing, right?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜