C# BLToolKit生成错误的SQL

C# BLToolKit生成错误的SQL,c#,sql,linq,bltoolkit,C#,Sql,Linq,Bltoolkit,我使用BLToolKit作为ORM映射器 我的问题是,它生成了错误的SQL 我有一个疑问: var qry = from i in s.Query<ChannelDTO>() join o in s.Query<StorageShelfDTO>() on i.Id equals o.ChannelID into p1 select new {i.Id, n = p1.Count()}; var qry2

我使用BLToolKit作为ORM映射器

我的问题是,它生成了错误的SQL

我有一个疑问:

var qry = from i in s.Query<ChannelDTO>() 
            join o in s.Query<StorageShelfDTO>() on i.Id equals o.ChannelID into p1
            select new {i.Id, n = p1.Count()};

        var qry2 = qry;
        qry2 = qry2.Where(x => x.n == 0);
        Debug.Print("Entrys: " + qry2.ToList().ToString());
缺少外部选择中的计数字段

但当我取消条件时:

 qry2 = qry2.Where(x => x.n == 0);

然后生成正确的SQL。

生成的查询是正确的

您有您的初始linq声明:

var qry = from i in s.Query<ChannelDTO>() 
            join o in s.Query<StorageShelfDTO>() on i.Id equals o.ChannelID into p1
            select new {i.Id, n = p1.Count()};
现在,当您将第二部分添加到查询(qry2)中时,这将添加到原始查询中,因为它使用的是延迟执行。因此,最终生成的查询在执行时如下所示:

var finalQuery = (from i in s.Query<ChannelDTO>() 
                 join o in s.Query<StorageShelfDTO>() on i.Id equals o.ChannelID into p1
                 select new {i.Id, n = p1.Count()}).Where(x => x.n == 0)

我知道有德弗德死刑,这也是我想要的!但是外部选择缺少计数,因此结果中没有填充值!当i filter==0时可以,但是当i filter例如>0时,它也不会被填充
SELECT
    (
        SELECT
            Count(*)
        FROM
            [WMS_StorageShelf] [t1]
        WHERE
            [i].[ID] = [t1].[ChannelID]
    ) as [c1],
    [i].[ID] as [Id]
FROM
    [WMS_Channel] [i]
var finalQuery = (from i in s.Query<ChannelDTO>() 
                 join o in s.Query<StorageShelfDTO>() on i.Id equals o.ChannelID into p1
                 select new {i.Id, n = p1.Count()}).Where(x => x.n == 0)
var qry = (from i in s.Query<ChannelDTO>() 
            join o in s.Query<StorageShelfDTO>() on i.Id equals o.ChannelID into p1
            select new {i.Id, n = p1.Count()}).ToList();