DataConnector | ComponentOne
ADO.NET provider for Dynamics 365 Sales / LINQ Queries
In This Topic
    LINQ Queries
    In This Topic

    LINQ queries demonstrate how to operate and query the Dynamics 365 Sales objects wrapped in an Entity Framework data model. Listed below are some examples of LINQ queries supported by the Entity framework.

    Select and Filter

     The following query searches for particular records from the database.

    var records =
             from p in context.Contracts
             where p.Title == "AGR-04" 
             select p;


    You can also search for strings within strings. The following example retrieves all the entities with a value that contains "con".

    var records =
             from p in context.Contracts
             where p.Title.Contains("con")
             select p;


     The following example limits the results returned to 10. This helps to limit display of records.

    var records =
            (from p in context.Contracts
             select p).Take(10);

    Order By

    The following example displays account records sorted in descending order. This helps to arrange items in a particular order.

    var records =
            (from Accounts in context.Accounts.Take(10)
             orderby Accounts.Name descending
             select Accounts).Take(10); ;


    The following example counts all entities that match a given criterion. 

    var count =
          (from p in context.Contracts
           select p).Count(); //count number of records in contract collection


    The following example groups entities based on a given criterion.

    var queryCity =
            from b in context.Accounts.Take(5)
            group b by b.Address1_Composite into newGroup
            orderby newGroup.Key descending
            select newGroup;


    The provider supports standard LINQ joins. The following is an example of a cross join between Accounts and Contracts.

    var records =
            (from c in context.Contracts.Take(10)
             from a in context.Accounts.Take(10)
             select new { c, a }).Take(20);