Search code examples
dynamics-crmdynamics-crm-2013

How to bulk load CRM custom entities


I'm using CRM 2013 and I would like to return a large number of custom entities (around 100) based on values in a list.

I can't do context.MyCustomEntity.Where(i=>list.Contains(i.Id));

I can't use RetrieveMultiple since I want to update these entities and send them back to the server.

So I'm forced to call context.MyCustomEntity.Where(i=>i.Id == id) in a loop.

Is there somewhere to prefetch the entities from the context? Or call execute on the where clause in a loop?


Solution

  • If you already have the Id's and you don't need to reference any existing dynamic values on the records, you can just update the records. Here's an example:

    var toUpdate = new MyCustomEntity{Id=id};
    // update appropriate values
    orgService.Update(toUpdate);
    

    However, if you do need to update the fields dynamically, you could chunk the retrievals by using PredicateBuilder to do a dynamic OR condition, but you are limited on the number of criteria you can add to your query. Let me know if this is a path you need to go down, and I can provide more guidance.