简体   繁体   English

有人可以解释一下这个 LINQ 查询的作用吗?

[英]Can someone please explain what this LINQ query does?

I am having trouble understanding this LINQ query.我无法理解这个 LINQ 查询。 This is what I think is happening.这就是我认为正在发生的事情。

1. from stat in XpoSession.Query<STUDENT>()
2. where stat.ID_PERSON.DT_BIRTH >= DateTime.Now.AddYears(-20)
3. && stat.Status.Where(val => val.CD_REASON == Constants.REASON_PLACED).Count() == 0
4. select stat.CD_STATUS.Trim()).ToList().GroupBy(val => val);

#1. #1。 Data source is STUDENT table from database.数据源是数据库中的STUDENT表。

#2. #2。 Gets all STUDENTS that are less than or equal to 20 years old.获取所有小于或等于 20 岁的 STUDENTS。

#3. #3。 This is the part I don't understand.这是我不明白的部分。 There is a STUDENT_STATUS table which has a CD_REASON column so I am assuming that stat.Status is really STUDENT_STATUS.CD_REASON and that gets passed into the lambda function and if it equals REASON_PLACED it does something with Count but not sure what.有一个STUDENT_STATUS表有一个CD_REASON列,所以我假设stat.Status真的是STUDENT_STATUS.CD_REASON并且它被传递到 lambda function 并且如果它等于REASON_PLACED

#4. #4。 Groups by CD_STATUS value.CD_STATUS值分组。

from stat in XpoSession.Query<STUDENT>()
where stat.ID_PERSON.DT_BIRTH >= DateTime.Now.AddYears(-20)
&& stat.Status.Where(val => val.CD_REASON == Constants.REASON_PLACED).Count() == 0
select stat.CD_STATUS.Trim()).ToList().GroupBy(val => val);

Looks like it's getting whatever the CD_STATUS value is for students who are more than 20 years old where their status isn't whatever Constants.REASON_PLACED value is and grouping them by the CD_STATUS value.对于 20 岁以上的学生,他们的状态不是任何Constants.REASON_PLACED值, CD_STATUS CD_STATUS

Without more context or additional code, it's not really possible to provide a better answer here.如果没有更多上下文或附加代码,实际上不可能在这里提供更好的答案。

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

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