我的where子句不适用于我的结果 [英] My where clause doesn't apply on my result

查看:275
本文介绍了我的where子句不适用于我的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个查询

_ctx.TestPackageReportDetails.GroupBy(i => new {i.Status, i.TestPackageId})
                .Where(m => m.Count(i => i.Status == "Accept") == 5)

结果:

而这个查询:

  var q2 = _ctx.TestPackages.ToList();

现在我在两个结果之间创建一个连接:

Now i create a join between two result :

 _ctx.TestPackageReportDetails.GroupBy(i => new { i.Status, i.TestPackageId })
                .Where(m => m.Count(i => i.Status == "Accept") == 5)
                .Join(_ctx.TestPackages, i => i.Key.TestPackageId, m => m.Id, (i, m) => new { pack = m, det = i })
                .Sum(i => i.pack.Size);

我根据 testpackageid 我需要大小值与此条件的总和其中(m => m.Count(i => i.Status ==Accept)== 5) ,但它不工作,并且查询使用此条件计算所有包大小而不是包大小其中(m => m.Count(i => i.Status ==Accept )== 5)

I create a joint based on testpackageid and i need the sum of size value with this condition Where(m => m.Count(i => i.Status == "Accept") == 5),but it doesn't work ,and the query calculates all package size not the package size with this condition Where(m => m.Count(i => i.Status == "Accept") == 5)

推荐答案

您需要过滤掉状态为不需要。还需要开始使用更加易读的优雅查询语法。像这样:

You need to filter out the records with the status that you don't need. Also you need to start to make use of the Elegant Query-Syntax which is more readable. Like this:

var sum = (from i in _ctx.TestPackageReportDetails
           where i.Status == "Accept"
           group i by new { i.Status, i.TestPackageId } into grouping
           where grouping.Count() == 5
           join m in _ctx.TestPackages
           on grouping.Key.TestPackageId equals m.Id
           select m.Size).Sum();

这篇关于我的where子句不适用于我的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆