-1

我有点坚持将 SQL 查询转换为 LINQ。任何机构都可以帮助我。这是我的查询

SELECT x.*
  FROM FilterType x
  JOIN (SELECT t.FilterType
          FROM FilterType t
          where FilterId in (7,15)
      GROUP BY t.FilterType
        HAVING COUNT(t.FilterType) > 1) y ON y.FilterType = x.FilterType

提前致谢。

4

2 回答 2

1

假设你有int[] ids = { 7, 15 }. 然后查询将如下所示:

from t in FilterType.Where(x => ids.Contains(x.FilterId))
group t by t.FilterType into g
where g.Count() > 1
from f in g
select f

或者使用方法语法:

FilterType.Where(x => ids.Contains(x.FilterId))
          .GroupBy(t => t.FilterType)
          .Where(g => g.Count() > 1)
          .SelectMany(g => g);

生成的 SQL 不会和你的完全一样,但结果应该是一样的。

于 2013-04-15T07:34:56.823 回答
0
from a in FilterType
join b in
    (
        from x in FilterType
        where (new int[]{7, 15}).Contains(x.FilterID)
        group x by new {x.FilterType} into g
        where g.Count() > 1
        select new {FilterType = g.Key.FilterType}
    ) on a.FilterType equals b.FilterType
select a;
于 2013-04-15T07:34:42.990 回答