Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I hope I've get what you want. I've simulated your <code>PurchaseOrder</code> with an array of dictionaries and I suppose, that formal parameter <code>y</code> in your lambda expression is derived from <code>IDictionary</code>, because I can see such expression <code>y["distributedOrderLineId"]</code>. Please correct me if I'm wrong in my assumptions. The solution is to check whether key is set by calling <code>order.ContainsKey("id")</code>. You can see the example below</p> <pre><code>var firstItem = new Dictionary&lt;string, string&gt;{{"id", "11"}}; var secondItem = new Dictionary&lt;string, string&gt;{{"id", "12"}}; var thirdItem = new Dictionary&lt;string, string&gt;(); // id is not set, as distributedOrderLineId in your example var fourthItem = new Dictionary&lt;string, string&gt;{{"id", "14"}}; var PurchaseOrder = new [] {firstItem, secondItem, thirdItem, fourthItem}; var quantity = 4; var orderID = 12; var distributionsLeft = quantity - 1 - PurchaseOrder.Where(order =&gt; order.ContainsKey("id") &amp;&amp; int.Parse(order["id"]) == orderID).Count(); Console.WriteLine (distributionsLeft); </code></pre> <p><strong>Edit:</strong> Could you please try to use next query, just to see if it work? We can then try to do some optimizations if it works fine.</p> <pre><code>PurchaseOrder.Where(y =&gt; y.OrderProperties.Any(z =&gt; z.Key == "distributedOrderLineId")) .ToList() .Where(y =&gt; y["distributedOrderLineId"] == ol.OrderLineId.ToString()) .Count(); </code></pre> <p><strong>Optimized version</strong>: I've tried to optimize version given above from performance and readability points of view, but note - I cold be wrong, because I haven't run that query. I've changed it only by analyzing uCommerce documentation regarding <a href="http://www.ucommerce.dk/docs/html/T_UCommerce_EntitiesV2_OrderLine.htm" rel="nofollow">OrderLine</a> and <a href="http://www.ucommerce.dk/docs/html/T_UCommerce_EntitiesV2_OrderProperty.htm" rel="nofollow">OrderProperty</a>. Also note, that I've used different names for formal parameters in lambdas - just to get rid of mess with y and z. </p> <pre><code>string orderLineId = ol.OrderLineId.ToString(); PurchaseOrder .Count(order =&gt; order.OrderProperties.Any(property =&gt; property.Key == "distributedOrderLineId" &amp;&amp; property.Value == orderLineId)); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload