在 ASP.NET Core-6 Web API 物體框架中,我有員工休假模型,如下所示:
public class Employee
{
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
public class LeaveApplication
{
public Guid Id { get; set; }
public Guid EmployeeId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public PaymentStatus PaymentStatus { get; set; }
public bool? IsApproved { get; set; }
public virtual Emmployee Employee { get; set; }
}
我想使用EndDate以及IsApproved為 true 的情況下獲取休假將在未來 3 天內結束的員工串列。
注意:我正在使用物體框架
我如何實作這一目標?
謝謝
uj5u.com熱心網友回復:
我認為您可以使用如下查詢:
var next3Day = DateTime.Now.Date.AddDays(4);
var employees = context.LeaveApplications
.Where(r=> r.IsApproved == true && r.EndDate > DateTime.Now && r.EndDate < next3Day).Select(r=> r.Emmployee )
.ToArrayAsync();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/519459.html
上一篇:DI容器中包含資料訪問層的問題
下一篇:將字串轉換為int以進行比較