Posts

Showing posts with the label LINQ

LINQ Grouping through SelectMany - Powerful!

This is the first time I use this feature and I love it very much! What this feature does is that it flattens your object in relation to your defined selected child object. So for example, if I have a list of Item object and that object has a List  of Category  (imagine Item has N:N relationship to Category) and I want to be able to group it based on the Category and display it in such a way so it looks like this: Category 1 Item 1 Item 2 Item 3 Category 2 Item 2 Item 4 and so on.. It is easy to get that structure using LINQ! That's all you need to do! ^_^ Hope this helps, Andreas

CRM 2011 LINQ Left Join Through Entity Reference

Let's say we have a custom lookup field new_accountid on our phonecall activity (don't ask me why I don't just use from/to field :)) and that field is NOT a required field. We want to get the account number using LINQ in our code somehow. This is the way to do it. The trick is that we have to check whether the new_accountid is null and combine those records with the ones that are null. Hope this helps, Andreas