0

我有以下 linq:

    var result2 = Psl_Pt
                .Where(w => w.PaslNum == 33979)
                .GroupBy(a => new { a.GroupId })            
                .Select(a =>
     new  
     {
            Publish = a.All(g => g.Publish)

     });

什么相当于:

Publish = a.All(g => g.Publish) 

从我看到的

.All(g => g.Publish) 

方法:

publish = 1

这是选择语句:

select groupid from Psl_Pt
where publish = 1 and paslnum = 33979
group by groupid 

请让我知道转换为 sql 是否正确

4

1 回答 1

1

All()如果所有成员都满足条件,则返回 true,在您的情况下Publish == true。所以一个 SQL 等价物是:

SELECT groupid, SUM(NOT publish) as AnyNotPublish
WHERE paslnum = 33979
GROUP BY groupid
HAVING AnyNotPublish = 0;

如果不是,您必须将发布转换为整数。

于 2012-11-12T19:30:14.323 回答