简体   繁体   English

PredicateBuilder和LINQ to CRM

[英]PredicateBuilder and LINQ to CRM

I'm trying to pull all the instances of a workflow that have ran (from the AsyncOperationBase table) with a number of predicates. 我试图提取具有多个谓词的(从AsyncOperationBase表中)运行的工作流的所有实例。

I know you can't use something like myArray.Contains(x.WorkflowActivationId.Id) so I'm trying to build a predicate dynamically with PredicateBuilder 我知道您不能使用诸如myArray.Contains(x.WorkflowActivationId.Id)类的东西,因此我正在尝试使用PredicateBuilder动态构建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: 但是我最终得到了很多LINQ to CRM可怕的异常:

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 ? 有任何想法吗 ?

I think I will need to circumvent LINQ to CRM's limits by doing this 2 part. 我认为我需要通过执行这两个步骤来绕过LINQ达到CRM的极限。

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. 然后,我就可以拥有完整LINQ访问t的内容。

var y = t.Where(x => myArray.Contains(x.WorkflowActivationId.Id)).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM