KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have written a Linq to CRM query using CRM 2011 RC (v5) LINQ-to-CRM provider. I have a locally declared List<T> which I want to join to a CRM entity and I want the query to be executed on the CRM Server. An example might help: MyObject myObject = new MyObject(); List<myAccount> myAccountsList = new List<myAccount>(); myAccountsList.Add(new myAccount() {AccountNumber = "123"}; myAccountsList.Add(new myAccount() {AccountNumber = "456"}; myObject.ListOfAccounts = myAccountsList; var accountsQuery = from ax in myObject.ListOfAccounts join a in orgContext.CreateQuery<customAccountEntity>() on ax.AccountNumber equals a.account_number select a; foreach(var item in accountsQuery) { Console.WriteLine("Id of record retrieved: " + a.Id.ToString()); } The code above compiles and executes, however, the filtering of the records is being performed locally after retrieving the entire CRM entity recordset. Obviously when the CRM entity contains thousands of rows the query will perform poorly or even timeout. I have read about IQueryable and IEnumerable and tried converting the List using the AsQueryable() extension method, which had no effect. I need my above Linq query to run SQL like this: SELECT a.* FROM customAccountEntity AS a WHERE a.account_number IN ('123', '456'); Or using a temporary table if wanted to join on multiple fields. How can I accomplish this?
Tags (comma-separated)
Save Edits
Cancel