0
如何摆脱“If then else”?Linq to Entities
If qShoppingCartByCartID.Invoke(_context).Count > 0 Then
Return qShoppingCartByCartID.Invoke(_context).Select(Function(x) x.Products.UnitCost - x.Products.SalePrice).Sum
Else
Return 0
End If
查询的select部分触发错误,因为列表为空。我不认为你在C#中的查询也会工作。因为列表是空的,所以没有选择部分的值(x.Products.UnitCost -x.Products.SalePrice)。 – arlen 2011-05-12 15:24:15
我很困惑 - 哪个列表是空的? x.Products?如果将投影放入Sum中会发生什么 - 例如'.Sum(Function(x)x.Products.UnitCost - x.Products.SalePrice)'? – Stuart 2011-05-12 16:30:09