Multiple keyword search with a LINQ query using the CRM API

One of my customers wanted a simple web service to access CRM data from a web portal he was creating. The normal CRM API was to complex for this so we decided to make a WCF service that connected to CRM via the CRM API. One of the functions he wanted was a multiple keyword search.

var searchfrase = "hebbink com";
var keywords = searchfrase.Split(' ');
var query = AccountSet;

foreach (var x in keywords)
{
    query = query.Where(a => (a.AccountNumber.Contains(x) || a.Name.Contains(x)));
}

var accounts = query.ToList();

foreach (var account in accounts)
{
    Console.Write(account.Name + Environment.NewLine);
}

Just run this piece of code in LINQPad for CRM as a C# Statement and you will get the following result:



Works like a charm :-)

Comments (4) -

  • custom essay writing service

    12/8/2016 4:57:06 AM |

    Thank you for share this information i like this information very much and its very useful to me. i have more some doubts about this API please share more information about this Multiple keyword search with a LINQ query.

  • paper writing service

    2/8/2017 7:14:11 PM |

    That was interesting. Thank you for adding those materials here. I think that some of those aspects are already familiar to us.

Loading