I have been trying to get my head around LINK and OData today. OData was really giving me the run around, trying to bring the sample into a piece of Javascript was very frustrating.
I am a big fan of Early bound data in CRM 2011, I just like to know what I am using rather than the dynamic late binding, strong typing means you catch any problems in the code when compiling it and saves you a bunch of time debugging misspelt entites in strings.
I couldn’t figure out how to get the results of a Linq query in a early bound entity. In link you often just use the Var variable and then LINQ converts the results into the correct type.
The SDK also didn’t seem to have any examples but I had been reading about LINQ for the 70-515 .NET web apps exam. I knew the result had to be IEnumerable so you can go through the results.
The quick answer is you have use this
IEnumerable<Account>
instead of a
Var
here is a snippet of my code. if anyone can tell me the easiest way to display code in WordPress that would be appreciate, please leave me some advice in the comments. This blog post has some good information on LINQ queries
_service = (IOrganizationService)_serviceProxy; OrganizationServiceContext orgContext = new OrganizationServiceContext(_service); IEnumerable<Account> accounts = from a in orgContext.CreateQuery<Account>() select new Account { Name = a.Name, Address1_County = a.Address1_County }; System.Console.WriteLine("List all accounts in CRM"); System.Console.WriteLine("========================"); foreach (Account a in accounts) { System.Console.WriteLine(a.Name + " " + a.Address1_County); } System.Console.WriteLine(); System.Console.WriteLine("<End of Listing>"); System.Console.WriteLine(); System.Console.WriteLine();