DataConnector | ComponentOne
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. Below are some examples of LINQ queries supported by the Entity framework.

    Contains

    Retrieve all records from the Books table that contain "A" in their Author name.

    C#
    Copy Code
    var records = from p in context.Books
                  where p.Author.Contains("A")
                  select p;
    Count

    Count all entities that match a given criterion.

    C#
    Copy Code
    var _count = (from p in context.Books
                  select p).Count();
    Filter

    Select records from the table Books that belong to Location_City equal to Delhi.

    C#
    Copy Code
    var records = from p in context.Books
                  where p.Location_City == "Delhi"
                  select p;
    Group By

    Group records from the Books table based on the Location_City property. The groups are then ordered in descending order based on the Location_City.

    C#
    Copy Code
    var booksTable = context.Books.AsEnumerable();
     var queryBooks = from b in booksTable
                      group b by b.Location_City into newGroup
                      orderby newGroup.Key descending
                      select newGroup;
    Join

    Cross join between Books and Employees tables.

    C#
    Copy Code
    var records = from b in context.Books
                  from e in context.Employees
                  select new { b, e };
    Limit

    Retrieve the first 10 records from the Books table.

    C#
    Copy Code
    var records = (from p in context.Books
                       select p).Take(10);
    Order By

    Sort records from the Books table by Title in descending order.

    C#
    Copy Code
    var records = from p in context.Books
                          orderby p.Title descending
                          select p;