[]
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.
var records = from p in context.Books
where p.Author.Contains("A")
select p;
Count
Count all entities that match a given criterion.
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.
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.
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.
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.
var records = (from p in context.Books
select p).Take(10);
Order By
Sort records from the Books table by Title in descending order.
var records = from p in context.Books
orderby p.Title descending
select p;