C# 当CreatedDate位于Date1var&;之间时,如何使用where子句编写此代码;Date2var?
当CreatedDate介于Date1var和Date2var之间时,如何使用where子句编写此代码C# 当CreatedDate位于Date1var&;之间时,如何使用where子句编写此代码;Date2var?,c#,linq,C#,Linq,当CreatedDate介于Date1var和Date2var之间时,如何使用where子句编写此代码 return _context.Logs.Where(x => x.ApplicationID == applicationId) .OrderByDescending(x => x.ID) .Take(count) .Select(record => new LoggingLogic.e
return _context.Logs.Where(x => x.ApplicationID == applicationId)
.OrderByDescending(x => x.ID)
.Take(count)
.Select(record => new LoggingLogic.entities.Log
{
DataL = record.Data,
LogMessage = record.Message,
CreatedDate = record.CreateDate,
ApplicationName = record.Application.Name,
Environment = record.Application.Environment.EnvironmentName,
ID = record.ID
});
试试这个
return _context.Logs.Where(x => x.ApplicationID == applicationId && x.CreatedDate >= Date1Var && x.CreatedDate <= Date2Var)
.OrderByDescending(x => x.ID)
.Take(count)
.Select(record => new LoggingLogic.entities.Log
{
DataL = record.Data,
LogMessage = record.Message,
CreatedDate = record.CreateDate,
ApplicationName = record.Application.Name,
Environment = record.Application.Environment.EnvironmentName,
ID = record.ID
});
return\u context.Logs.Where(x=>x.ApplicationID==ApplicationID&&x.CreatedDate>=Date1Var&&x.CreatedDate x.ID)
.记(数)
.选择(记录=>new LoggingLogic.entities.Log
{
DataL=记录。数据,
LogMessage=record.Message,
CreatedDate=record.CreateDate,
ApplicationName=record.Application.Name,
环境=record.Application.Environment.EnvironmentName,
ID=record.ID
});
将您的Where()
更改为Where(x=>x.ApplicationID=ApplicationID&&x.CreatedDate>=Date1var&&x.CreatedDate谢谢。如果Date1var和Date2Var是同一个日期呢?它的类也大于或等于,所以它也应该工作:)