[]
LINQ queries demonstrate how to operate and query the CSV 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 "Agriculture" in their Industry name.
var histories = from p in context.Books
where p.Industry_name.Contains("Agriculture") //using Contains to display Industry names that contain "Agriculture"
select p;
Count
Count all entities that match a given criterion.
var _count = (from p in db.SampleCSV
select p).Count(); //Count Query based on the number of records selected
Select and Filter
Select records from the table SampleCSV that belong to the Year equal to 2011.
var histories = from p in db.SampleCSV
where p.Year== 2011
select p;
Limit
Select the first 2 records.
var histories = (from p in db.SampleCSV
select p).Take(2); //taking 2 records
Order By
Sort records form the table SampleCSV by the Year in descending order.
var histories = (from p in db.SampleCSV
orderby p.Year descending //Implementing Order By
select p).Take(2); //taking 2 records
Group By
Group records from the SampleCsvs table based on the Age property. The groups are then ordered in descending order based on the Age.
var sampleTable = context.SampleCsvs.AsEnumerable();
var querySample = from b in sampleTable
group b by b.Age into newGroup
orderby newGroup.Key descending
select newGroup;