我试图提取(从AsyncOperationBase表中)运行的工作流的所有实例,这些实例都有许多谓词。
我知道您不能使用像myArray.Contains(x.WorkflowActivationId.Id)这样的东西,所以我尝试用PredicateBuilder动态地构建一个谓词
到目前为止,我的情况如下:
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();但是,我最终得到了许多LINQ可怕的例外:
Invalid 'where' condition. An entity member is invoking an invalid property or method.据我所知,要避免这个错误,您需要“爬行”属性。比如:
predicate = predicate.Or(x => x.WorkflowActivationId == s);必须更改为
predicate = predicate.Or(x => x.WorkflowActivationId.Id == s);此外,谓词的左侧必须是一个实体属性。再一次,据我所知,我的谓词满足了这些要求,所以我有点不知所措。
有什么想法吗?
发布于 2014-06-18 15:16:49
我想我需要绕过LINQ的限制,做这2部分。
第一次:
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();我现在真的只需要这两个属性。
这样我就可以完全访问t的内容了。
var y = t.Where(x => myArray.Contains(x.WorkflowActivationId.Id)).ToList();https://stackoverflow.com/questions/24288617
复制相似问题