0

I'm trying to pull all the instances of a workflow that have ran (from the AsyncOperationBase table) with a number of predicates.

I know you can't use something like myArray.Contains(x.WorkflowActivationId.Id) so I'm trying to build a predicate dynamically with PredicateBuilder

Here's what I have so far:

var predicate = PredicateBuilder.False<Service.AsyncOperation>();

//Apparently, checking for null is suppose to prevent my issue from happening...
predicate = predicate.And(x => x.Name == searchWorkflowDefinitionText.Text);
predicate = predicate.And(x => x.StatusCode != null);
predicate = predicate.And(x => x.StatusCode.Value == 10);
predicate = predicate.And(x => x.WorkflowActivationId != null);


foreach (Guid s in listBox3.Items)
{
    predicate = predicate.Or(x => x.WorkflowActivationId.Id == s);
}


var r = (from c in xrm.CreateQuery<Service.AsyncOperation>().AsExpandable().Where(predicate)
                         select c).ToList();

But I end up getting the much LINQ to CRM dreaded exception:

Invalid 'where' condition. An entity member is invoking an invalid property or method.

As far as I know, to not get this error, you need to 'crawl down' attributes. Things like:

predicate = predicate.Or(x => x.WorkflowActivationId == s);

Have to be changed to

predicate = predicate.Or(x => x.WorkflowActivationId.Id == s);

And also, the left hand side of the predicate must be a entity attribute. Again, as far as I know, my predicate satisfies those requirements so I am a bit at a loss here.

Any ideas ?

Francis Ducharme
  • 4,848
  • 6
  • 43
  • 81
  • remember that CRM LINQ implementation has several limits, I didn't check but maybe this is one. – Guido Preite Jun 18 '14 at 15:00
  • @GuidoPreite Yes I know. Which is why I asked so I'd know what to blame: me and my misunderstanding of predicates, or the weak LINQ to CRM 2011 provider that doesn't really lets you access your data :) – Francis Ducharme Jun 18 '14 at 15:01

1 Answers1

0

I think I will need to circumvent LINQ to CRM's limits by doing this 2 part.

1st:

var t = xrm.AsyncOperationSet.Where(x => x.StatusCode.Value == 10 && x.Name == wkname).Select(y => new Service.AsyncOperation
                {
                    AsyncOperationId = y.AsyncOperationId.Value,
                    WorkflowActivationId = y.WorkflowActivationId
                }).ToList();

I really need only these two attributes for the moment.

Then I'll be able to have full LINQ access to t's content.

var y = t.Where(x => myArray.Contains(x.WorkflowActivationId.Id)).ToList();
Francis Ducharme
  • 4,848
  • 6
  • 43
  • 81