Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 已忽略EF Core 2 GroupBy计数谓词_C#_Asp.net_Ef Core 2.0 - Fatal编程技术网

C# 已忽略EF Core 2 GroupBy计数谓词

C# 已忽略EF Core 2 GroupBy计数谓词,c#,asp.net,ef-core-2.0,C#,Asp.net,Ef Core 2.0,我目前拥有以下代码: var result = query<Items>() .Where(x => x.Id == someId) .SelectMany(x => x.SubItems) .GroupBy(x => x.SubItemId) .Select(x => new ItemModel { S

我目前拥有以下代码:

var result = query<Items>()
            .Where(x => x.Id == someId)
            .SelectMany(x => x.SubItems)
            .GroupBy(x => x.SubItemId)
            .Select(x => new ItemModel
            {   
                SubItemId = x.Key,
                SpecialItemCount = x.Where(y => y.IsSpecial == false).Count(),
            })
            .ToList()...
var result=query()
.Where(x=>x.Id==someId)
.SelectMany(x=>x.SubItems)
.GroupBy(x=>x.SubItemId)
.选择(x=>new ItemModel
{   
SubItemId=x.键,
SpecialItemCount=x.Where(y=>y.IsSpecial==false).Count(),
})
.ToList()。。。

当我调用“Count()”时,它查询所有子项Count,忽略谓词“y.IsSpecial”。我在EF Core 2.0.X和EF Core 2.1 preview 2上试过,这可能是一个bug吗?

您需要升级到支持GroupBy的EF Core 2.1:

EF Core 3.0也存在同样的问题。似乎是EF中的错误-您可以使用

SpecialItemCount = x.Sum(y => y.IsSpecial ? 0 : 1)
而不是

SpecialItemCount = x.Count(y => y.IsSpecial == false)

我相信,
GroupBy
尚未在EF Core中实现,因此这将把所有表拖到内存中,并在本地进行分组。它在2.1中受支持,ConsoleEyes中没有警告,但不确定它的工作情况如何。注意,您也可以将计数写为
x.count(y=>!y.IsSpecial)
将在有时间时查看。为了清楚起见,它不会发生在2.0.2上,对吗?只有在2.1预演2?这是2.1预演2决赛。不幸的是,我不记得它的确切版本(2.0.x)