这就是我得到的:
int? productID = (ClientProduct != null ? (int?)ClientProduct.ProductID : null);
result = (from po in ((Chase_Media_Pro_Entity_Model)this.NavigationItem.ObjectContext).raPurchaseOrder_List
where po.ClientID == Client.CustomerID
&& ((object.Equals(po.ClientProductID, productID)) || (po.ClientProductID == (productID ?? po.ClientProductID)))
&& (po.Is_Active == (isActive ?? po.Is_Active))
&& (po.IsApproved == (isApproved ?? po.IsApproved))
orderby po.Is_Active descending, po.IsApproved ascending
select po);
有没有办法改善这一行:
&& ((object.Equals(po.ClientProductID, productID)) || (po.ClientProductID == (productID ?? po.ClientProductID)))
这是我获得正确结果的唯一方法。
答案 0 :(得分:3)
&& (!productID.HasValue || (productID == po.ClientProductID))
答案 1 :(得分:1)
怎么样
&& ((productID.HasValue && po.ClientProductID.HasValue) ? po.ClientProductID.Value = productID.Value : true)