简体   繁体   English

比较两个值之间的复杂子查询

[英]Compare complex subquery between two values

I have repository with students and I want to get some students who have grades count in between 0 and 2. 我有学生资料库,我想让一些成绩在0到2之间的学生。

This is my code: 这是我的代码:

_unitOfWork.Repository<Student>().Get(o => o.OrganizationId == organizationId
                && o.Grades.Where( o1 => o1.LastVersion
                        && o1.Type == 5
                        && o1.Value == 1).Count() > 0 
                && o.Grades.Where( o1 => o1.LastVersion
                        && o1.Type == 5
                        && o1.Value == 1).Count() <= 2 );

This code is working, but my question is how to change this query with less code. 这段代码有效,但是我的问题是如何用更少的代码更改此查询。

Is there any way to replace Count with some variable and not use it two times in query? 有什么方法可以用某些变量替换Count而不在查询中使用两次?

something like this? 这样的东西?

 var values = Enumerable.Range(1, 2);

 _unitOfWork.Repository<Student>().Get(o => o.OrganizationId == organizationId
            && values.Contains(
                o.Grades.Where( o1 => o1.LastVersion
                    && o1.Type == 5
                    && o1.Value == 1).Count()
               ));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM