如何使用EF C按月和年查询数据#

时间:2018-01-17 17:57:30

标签: c# entity-framework

我正在使用此代码按月和年份获取数据,但这不是正确的结果。见代码

var result = uow.CompliedInspectionRepository.All
    .Where(c => c.IsCompleted == false || c.IsCompleted == null
                && (c.DueDate.Value.Month == i && c.DueDate.Value.Year == year));

任何建议或如何在EF中完成?

1 个答案:

答案 0 :(得分:2)

您可能将括号放在错误的位置

c.IsCompleted == false || c.IsCompleted == null && (c.DueDate.Value.Month == i && c.DueDate.Value.Year == year) 

我认为这会返回结果 where(iscompleted为false或iscompleted为null) 和(月份和年份匹配)

你可以尝试

(c.IsCompleted == false) || (c.IsCompleted == null && c.DueDate.Value.Month == i && c.DueDate.Value.Year == year)

其中iscomplete为false或 (iscomplete为null,月份和年份匹配)