Linq where子句与DbFunctions.DiffDays和字符串比较不起作用

时间:2018-03-05 06:26:15

标签: c# linq

我有一个Linq查询,以便让所有逾期超过30天的发票的客户。

当我运行下面的查询时,它不会返回任何结果,如果我删除a.Status,它将返回结果。

var clients = (from a in ClientTable
           join b in Invoices on a.ClientId equals b.InvoiceId
           where DbFunctions.DiffDays(TodayDate, b.InvoiceDueDate) > 30 && a.Status == "Active"
           group a into c by a.id   
           select c).ToList();

请帮忙

1 个答案:

答案 0 :(得分:0)

看起来状态列中存在NULL值的问题。通过包含object.Equals(customer.Status,“Active”)来解析它。 Handling null values in where clause using LINQ-to-SQL

var clients = (from a in ClientTable
           join b in Invoices on a.ClientId equals b.InvoiceId
           where DbFunctions.DiffDays(TodayDate, b.InvoiceDueDate) > 30 && object.Equals(a.Status,"Active")
           group a into c by a.id   
           select c).ToList();