如何根据多个密钥来检索实体?

时间:2017-12-28 16:26:48

标签: c# dynamics-crm entity crm dynamics-crm-2016

我根据与其他实体的过滤检索实体,我需要添加另一个过滤级别 - 将lists = [(2012, 'january', 'monday'), (2012, 'february', 'monday'), (2012, 'january', 'tuesday')] day = input("Give day: ") #monday def select_monday(lists, day): list2 = [] for list in lists: if list[2] == day: #from here I'm stuck and do not know how to continue list2.append(list) return list2 添加到当前链接实体,是否可能?写它的方式是什么?

这是我目前正常运作的代码。

linkentity

得出结论:我需要根据entity3向entity2添加过滤。

更新:我添加了以下代码:

QueryExpression query = new QueryExpression("entity1");
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));          
query.ColumnSet = new ColumnSet("entity1Id");
LinkEntity Link = new LinkEntity("entity1", "entity2", "entity2Id", "entity2Id", JoinOperator.LeftOuter);
Link.LinkCriteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));         
    Link.Columns = new ColumnSet("entity2Data");
     Link.EntityAlias = "entity2";
    query.LinkEntities.Add(Link);

我得到一个例外,即entity1不识别entity2Id字段,** entity1字段的名称很遗憾有点不同**但在添加第三个实体之前它工作正常

1 个答案:

答案 0 :(得分:0)

与1st Link实体相同。除现有代码外,添加另一个链接实体,如下所示:

        LinkEntity Link2 = new LinkEntity("entity2", "entity3", "entity3Id", "entity3Id", JoinOperator.LeftOuter);
        Link2.LinkCriteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));         
        Link2.Columns = new ColumnSet("entity3Data");
        Link2.EntityAlias = "entity3";
        query.LinkEntities.Add(Link2);