I'm trying to count how many orderlines (ol) that have the custom field "distributedOrderLineId" equal to the orderline id of the current iteration.
The thing is, that not every orderline has this custom field defined. How can I make LINQ skip the orderlines with an undefined custom field instead of throwing an error.
Please refer to the code below.
var distributionsLeft = ol.Quantity - 1 - PurchaseOrder.All().Where(y => int.Parse(y["distributedOrderLineId"]) == ol.Id).Count();
Best regards, Brinck10
EDIT
I've tried the following piece of code using any:
PurchaseOrder.All().Where(y => y.OrderProperties.Any(z=>z.Key=="distributedOrderLineId")).Where(a=>a["distributedOrderLineId"]==ol.OrderLineId.ToString()).Count();
Unfortunately it doesn't work. The error I get on the stack trace is:
[NotSupportedException: System.String get_Item(System.String)]
NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression expression) +206
EDIT END