c# - 参数 2:不能从 'bool' 转换为 'System.DateTime?'
问题描述
我尝试在两个日期之间创建一个数据范围:开始和结束。
为此,我有以下查询:
public DateTime CreatedAt { get; set; }
private IQueryable<Alert> GetAlerts(int organisationId, DateTime? beginDate = null, DateTime? endDate = null, bool includeDone = false)
{
var query =
_patientDbContext.Alerts
.Where(i => i.OrganisationId == organisationId && i.CreatedAt = endDate.ToString() <= beginDate.ToString());
if (!includeDone)
{
query = query.Where(i => !i.IsDone);
}
query = query.OrderBy(i => i.Deadline);
return query;
}
但我收到此错误:
参数 2:不能从 'bool' 转换为 'System.DateTime?'
我究竟做错了什么?
解决方案
这是因为您的子句中有一个赋值(=
符号)Where
i.CreatedAt = endDate.ToString() <= beginDate.ToString()
你想要做的是这个,假设CreatedAt
是DateTime
:
var query = _patientDbContext.Alerts.Where(i =>
i.OrganisationId == organisationId &&
(beginDate == null || i.CreatedAt => beginDate.Value) &&
(endDate == null || i.CreatedAt <= endDate.Value)
);
推荐阅读
- flutter - 更改开关的颜色 - FormBuilderSwitch - flutter
- python - Statsmodels Logit 为伪 R 平方提供 inf
- javascript - 根据 id 映射两个对象时如何从一个对象获取数据?
- angular - 如何更新 sessionStorage - Angular
- symfony - Symfony Workflow 中的marking_store“服务”选项是什么
- c++ - 从外部访问类对象
- angular - 使用自定义日期过滤器过滤 PrimeNg 表抛出错误,说值未定义
- rest - 如何将来自外部 Rest API 调用的响应发送到在 Thingsboard 的规则链中创建的控制台?
- c# - 使用 DataTrigger 将数据绑定到按钮样式
- matlab - Matlab“ground truth labeler”在ros bag播放中非常慢