gpt4 book ai didi

c# - LINQ- Max where 条件

转载 作者:可可西里 更新时间:2023-11-01 08:51:10 45 4
gpt4 key购买 nike

我有一个定义如下的 TaskWeekUI 类:

 public class TaskWeekUI    {
public Guid TaskWeekId { get; set; }
public Guid TaskId { get; set; }
public Guid WeekId { get; set; }
public DateTime EndDate { get; set; }
public string PersianEndDate { get; set; }
public double PlanProgress { get; set; }
public double ActualProgress { get; set; } }

我写了这个查询:

 TaskWeekUI ti =  tis.First( t => t.PlanProgress > 0 && t.EndDate ==  tis.Where(p => p.PlanProgress != null && p.PlanProgress > 0).Max(w => w.EndDate));

这个查询是真的吗?我能写出比这更好的查询吗?

最佳答案

我认为您想要 PlanProgress > 0 具有最近的 EndDate 的那个。

TaskWeekUI ti = tis.Where(t => t.PlanProgress > 0)
.OrderByDescending(t => t.EndDate)
.FirstOrDefault();

关于c# - LINQ- Max where 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4562049/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com