1. Projection
Code
using(var ctx=new SchoolEntities())
{
ObjectQuery<Courses> courses = ctx.Courses;
IQueryable<Courses> allcourses = from c in courses
select c;
Console.WriteLine(courses.ToTraceString());
}
2. Where
using(var ctx=new SchoolEntities())
{
ObjectQuery<Courses> courses = ctx.Courses;
IQueryable<Courses> allcourses = from c in courses
select c;
Console.WriteLine(courses.ToTraceString());
}
Code
using(var ctx=new SchoolEntities())
{
ObjectQuery<Courses> courses = ctx.Courses;
IQueryable<Courses> allcourses = from c in courses
where c.CourseName == "Act"
select c;
}
3.Pagination
using(var ctx=new SchoolEntities())
{
ObjectQuery<Courses> courses = ctx.Courses;
IQueryable<Courses> allcourses = from c in courses
where c.CourseName == "Act"
select c;
}
Code
using(var ctx=new SchoolEntities())
{
ObjectQuery<Courses> courses = ctx.Courses;
IQueryable<Courses> allcourses = from c in courses
orderby c.CourseType
select c.Skip(0).Take(100);
}
4. Aggregation (Average, Max, Min, Count, Sum)
using(var ctx=new SchoolEntities())
{
ObjectQuery<Courses> courses = ctx.Courses;
IQueryable<Courses> allcourses = from c in courses
orderby c.CourseType
select c.Skip(0).Take(100);
}
using
(var ctx
=
new
SchoolEntities())
{
var older = ctx.Persons.Max(p => p.Age);
Console.WriteLine(older.Value);
}
5. Join
{
var older = ctx.Persons.Max(p => p.Age);
Console.WriteLine(older.Value);
}
using
(var ctx
=
new
SchoolEntities())
{
var query = from c in ctx.Courses
join d in ctx.CourseDetails
on d.CourseID equals c.CourseID
select new {
c, d.Info};
}
{
var query = from c in ctx.Courses
join d in ctx.CourseDetails
on d.CourseID equals c.CourseID
select new {
c, d.Info};
}
Reproduced in: https: //www.cnblogs.com/crossingdawn/archive/2009/07/27/1532212.html