我无法正确过滤记录。
q = q.LeftJoin<PurchaseInvoice, PurchaseInvoiceProjectLink>((pi, pipl) => pi.Id == pipl.PurchaseInvoiceId);
q = q.Where<PurchaseInvoiceProjectLink>(s => Sql.In(s.ProjectId, UserSession.ProjectIds)) || s == null );
s == null
部分不起作用,我看到它在sql查询中具体化为 OR ('{}' is null))
我不确定这是否是Servicestack ORM Lite中的一个错误,或者代码应该以其他方式编写。
====
好的。我已经解决了这个问题,如下所示(但仍在寻找不使用 pragma 的方法。
#pragma warning disable CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null'
q = q.Where<PurchaseInvoiceProjectLink>(s => ... || s.PurchaseInvoiceId == null);
#pragma warning restore CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null'
尝试
q = q.LeftJoin<PurchaseInvoice, PurchaseInvoiceProjectLink>((pi, pipl) => pi.Id == pipl.PurchaseInvoiceId).Where<PurchaseInvoiceProjectLink>(s => s.Id == null || UserSession.ProjectIds.Contains(s.ProjectId));