LINQ to Dynamics CRM Query filtering records locally

前端 未结 3 1542
囚心锁ツ
囚心锁ツ 2021-01-02 01:07

I have written a Linq to CRM query using CRM 2011 RC (v5) LINQ-to-CRM provider. I have a locally declared List which I want to join to a CRM entity and I want the q

3条回答
  •  难免孤独
    2021-01-02 01:48

    Edit: Try that one:

    MyObject myObject = new MyObject();
    List myAccountsList = new List();
    
    myAccountsList.Add(new myAccount() {AccountNumber = "123"};
    myAccountsList.Add(new myAccount() {AccountNumber = "456"};
    
    myObject.ListOfAccounts = myAccountsList;
    
    var accountNumbers = myObject.ListOfAccounts.Select(a => a.AccountNumber);
    
    var accountsQuery = orgContext.CreateQuery()
                                  .Where(a => accountNumbers.Contains(a.account_number));
    
    foreach(var item in accountsQuery)
    {
        Console.WriteLine("Id of record retrieved: " + a.Id.ToString());
    }
    

    Edit: if you query provider don't support Contains, build a Where condition with multiple OR, you can use predicate builder to make that easy

提交回复
热议问题