MSDN Library

Filter Multiple Entities with LINQ

[Applies to: Microsoft Dynamics CRM 2011]

You can create complex .NET Language-Integrated Query (LINQ) queries in Microsoft Dynamics CRM 2011. You use multiple Join clauses with filter clauses to create a result that is filtered on attributes from several entities.

Filter Multiple Entities Example

The following sample shows how to create a LINQ query that works with two entities and filters the result based on values from each of the entities.


Using svcContext As New ServiceContext(_serviceProxy)
 Dim query_where3 = From c In svcContext.ContactSet _
                    Join a In svcContext.AccountSet _
                    On c.ContactId Equals a.account_primary_contact.Id _
                    Where a.Name.Contains("Contoso") _
                    Where c.LastName.Contains("Smith") _
                    Select New With {Key .account_name = a.Name,
                                     Key .contact_name = c.LastName}

 For Each c In query_where3
  Console.WriteLine("acct: " & c.account_name & vbTab & vbTab _
                    & vbTab & "contact: " & c.contact_name)
 Next c
End Using

See Also

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.

Community Additions

Show:
© 2016 Microsoft