DataConnector | ComponentOne
ADO.NET provider for Salesforce / LINQ Queries
In This Topic
    LINQ Queries
    In This Topic

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

    Select and Filter

    Retrieve records from the Order table where the BillingState is "Delhi".

    C#
    Copy Code
    var records = from p in context.Order
                where p.BillingState == "Delhi"
                select p;
    Contains

    Retrieve records from the Order table where the AccountId property contains the letter "A" in its value.

    C#
    Copy Code
    var records = from p in context.Order
                where p.AccountId.Contains("A") //using Contains to display AccountId that have A. 
                select p;
    Limit

    Retrieve the first 10 records from the Order table.

    C#
    Copy Code
    var records = (from p in context.Order
                select p).Take(10); //taking 10 records
    Order by

    Retrieve all records from the Order table and sort them in descending order based on the AccountId property.

    C#
    Copy Code
    var records = (from p in context.Order
                orderby p.AccountId descending//Implementing Order By
                select p).Take(10); //taking 10 records
     Count

    Count all the entities that match a given criterion. 

    C#
    Copy Code
        var _count = (from p in context.Order
                    select p).Count();//Count Query based on the number of records selected
    Group By

    Group records from the Order table based on the BillingCity property.

    C#
    Copy Code
     var ordersTable = context.Order.AsEnumerable();
     var queryOrders = from b in ordersTable
                       group b by b.BillingCity into newGroup
                       orderby newGroup.Key descending
                       select newGroup;
    Joins

    Cross-join between the Status and BillingState tables.

    C#
    Copy Code
    var records = from b in context.Status
                from e in context.BillingState
                select new { b, e };//Defining Cross Join