DataConnector
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

     The following query searches for records that have a value "Delhi" for the BillingState column.

    var records = from p in context.Order
      where p.BillingState == "Delhi"
       select p;
    

    Contains

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

    var records = from p in context.Order
     where p.AccountId.Contains("A") //using Contains to display accountid have A in thier   name 
      select p;
    

     

    Limit

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

    var records = (from p in context.Order
     select p).Take(10); //taking 10 records
    

    Order By

    The following example executes a multicolumn sort. The results are sorted by Title in descending order. This helps to arrange items in a particular order.

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

    Count

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

    var _count = (from p in context.Order
      select p).Count();//Count Query based on number of records selected
    

    Group

    The following example groups entities based on a given criterion.

    var queryCity =
     from b in context.Order
       group b by b.BillingCity into newGroup //Linq Group Query based on city
        orderby newGroup.Key descending
          select newGroup;
    

    Joins

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

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