在以下 OUTER JOIN LINQ 查询中,我在Where
如果右侧行为空,则子句(如果 c.CustomerID 与外连接中的 ord.CustomerID 不匹配)。Question:如果下面的 ord.price 为 null,我该如何处理这种情况Where clause
Note:价格是类型可为空的列int?
.
Query1 = from c in Customers
join ord in Orders on c.CustomerId equals ord.CustomerId into cord
from t in cord.DefaultIfEmpty()
where t.price = null || t.price > 100
select new {CustName = c.Name, OrderID = (t == null ? 0 : t.OrderId)};
UPDATE:
抱歉,where 子句中有一个拼写错误。
- 正如@JeffMercado 指出的那样,应该是
t.price
and not ord.price
- 中缺少一个条款
Where
条款。我已将其更正为:where t.price = null || t.price > 100
。但现在我收到错误:operator || cannot be applied to operands of type '<null>' and 'int'
你可以这样做:
Query1 = from c in Customers
join ord in Orders on c.CustomerId equals ord.CustomerId into cord
from t in cord.DefaultIfEmpty()
where (ord.price ?? 0) > 100
select new {CustName = c.Name, OrderID = (t == null ? 0 : t.OrderId)};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)