c# - 如何在 LINQ Asp c# 中使用 group by
问题描述
对一些包含不良数据的报告进行逆向工程。使用 Linq 用 Asp.Net C# 编写的报告
我可以在数据库中编写查询,但无法转换为 Linq。
public StudentBehaviourActivityDTO GetStudentBehaviourActivity(
Guid userId)
{
List<DateTime> lastUpdatedDates = Uow.ActivityTrackingUnitValues
.Where(atuv => atuv.Last_Updated_On != null
&& atuv.TBH_Activity_Tracking_Unit
.StudentBehaviour
.Student
.TeamMembers
.Any(tm => tm.Id == userId))
.Select(atuv => (DateTime)DbFunctions
.TruncateTime(atuv.Last_Updated_On))
.ToList();
toList 中的这个加载是什么?我假设这是加载我的表:ActivityTrackingUnitValues
但是它也确实如此,看起来它也正在加入这些表
.StudentBehaviour
.Student
.TeamMembers
我想取 Last_Updated_On 的最大值(值),然后按学生分组
非常感谢任何帮助或解释。
解决方案
public StudentBehaviourActivityDTO GetStudentBehaviourActivity(
Guid userId)
{
List<DateTime> lastUpdatedDates = Uow.ActivityTrackingUnitValues
.Where(atuv => atuv.Last_Updated_On != null // check to make sure it's not null
&& atuv.TBH_Activity_Tracking_Unit
.StudentBehaviour //this references a class (generally a join, but it doesn't join!)
.Student //this references a class (generally a join, but it doesn't join!)
.TeamMembers //this references a class (generally a join, but it doesn't join!)
.Any(tm => tm.Id == userId)) // Checks to make sure it isn't null or has a count greater than 0
.Select(atuv => (DateTime)DbFunctions
.TruncateTime(atuv.Last_Updated_On)) // Returns the truncatedtime and nowthing else
.ToList(); // converts it to a list
据我所知,它确保班级有可用的成员。
推荐阅读
- javascript - display:block 不能识别 TR 中的 TD?
- android - 如何修复这个原始查询
- dialogflow-es - 如何在不使用后备意图的情况下保存语法错误的用户输入?
- python - 在两个文件之间共享函数
- swift - 如何在 SwiftUI 中删除“表单”的顶部空间?
- node.js - Nodejs从Promise Async Function返回对象并将其显示在网页上?
- python - 为什么我的 Python 服务器不能使用 select.select() 同时处理来自多个客户端的数据?
- pandas - 一次可以在索引值上使用 pct_change() 吗?
- c# - C# Linq 将 2 个 ObservableCollections 加入新的一个
- asp.net-core - 如何在 ASP.NET Core 3 和 Swashbuckle 5 中为 ProblemDetails 编写 ISchemaFilter?