【问题标题】:Get All Entities From EntityCollection Where Values Matches X从 EntityCollection 中获取值匹配 X 的所有实体
【发布时间】:2020-10-24 12:00:29
【问题描述】:

我想通过一个值从EntityCollection 中获取所有匹配的Entities,但我当前的语句只允许返回Entity,而不是EntityCollection

//only allow return 1 entity
var matchedRecords = allRecords.Entities.Where
                                (x => x.GetAttributeValue<EntityReference>
                                                         ("ccc_batchId").Id == batchId);

我可以知道如何调整上述查询吗?

【问题讨论】:

    标签: linq dynamics-crm entity entitycollection


    【解决方案1】:

    EntityCollection 只是一种存储多个实体的构造。

    我知道这并不理想,但您始终可以在实体列表中转换 allRecords.Entities 并针对它进行 LINQ 查询。

    您的代码可能返回一个实体的 IEnumerable 而不是单个实体(例如,在您的查询结束时,您可以放置​​一个 .ToList() 来获取实体列表。

    【讨论】:

      【解决方案2】:

      在 Guido 所说的基础上,还可以使用结果创建一个新的EntityCollection

      var matchedRecords = allRecords.Entities.Where(x => x.GetAttributeValue<EntityReference>("ccc_batchId").Id == batchId).ToList();    
      var matchedCollection = new EntityCollection(matchedRecords);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-25
        相关资源
        最近更新 更多