ADO.NET provider for OData / LINQ Queries
In This Topic
    LINQ Queries
    In This Topic

    LINQ queries demonstrate how to operate and query the OData 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 Location_City column.

    var records = from p in context.Books
               where p.Location_City == "Delhi"
               select p;


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

    var records = from p in context.Books
               where p.Author.Contains("A") //using Contains to display Authors have a in their name 
               select p;



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

    var records = (from p in context.Books
                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.Books
               orderby p.Title descending //Implementing Order By
               select p).Take(10); //taking 10 records


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

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


    The following example groups entities based on a given criterion.

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


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

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