AEF横空出世——查询语法详解

LINQ to Entity查询语法
允许开发人员使用LINQ表达式和LINQ标准查询运算表达式,对EDM的Object Context进行强类型的查询
在LINQ to Entity中的标准查询运算表达式方法
1、投影方法(Projection Methods)
Select、SelectMany
2、筛选方法(Filtering Methods)
Where
3、联接方法(Join Methods)
Join、GroupJoin
4、设定方法(Set Methods)
 All、Any、Concat、Contains、DefaultIfEmpty、Distinct、EqualAll、Except、Insertset、Union
5、排序 (Ordering Methods)
OrderBy、OrderByDescending、ThenBy、ThenByDescending、Reverse
6、群组方法(Grouping Methods)
GroupBy
7、聚合方法(Aggregate Methods)
Aggregate、Average、Count、LongCount、Max、Min、Sum
8、型别方法(Type Methods)
Convert、OfType
9、分页方法(Paging Methods)
ElemeAt、First、FirstOrDefault、Last、LastOrDefault、Single、Skip、Take、TakeWhile

Entity SQL查询语法


标准函数
1、 聚合标准函数(Aggregate Functions)
Avg、BigCount、Count、Max、Min、StDev、Sum
2、数学标准函数(Math Functions)
Abs、Ceiling、Floor、Round
3、字符串标准函数(Sting Functions)
Concat、IndexOf、Left、Length、LTrim、Replace、Reverse、Right、RTrim、Substring、
ToLower、ToUpper、Trim
4、日期和时间标准函数(Date & Time Functions
Year、Month、Day、Hour、Minute、Second、Millisecond、CurrentDateTime、CurrentDateTimeOffset
5、位元标准函数(Bitwise Functions
BitWiseAnd、BitWiseNot、BitWiseOr、BitWiseXor
6、标准函数(Other Canonical Functions)
NewGuid
7、关系一览表达式(Relationship Navigation Operator)
8、参考表达式(Reference Operators)
9、算术表达式(Arithmetic Operators)
10、比较运算表达式(Comparison Operators)
11、逻辑运算表达式(Logical Operators)
12、字符串联接表达式(String Concatenation Operator
13、类型运算表达式(Type Operators)
14、Case表达式(Case Expression)
15、设定运算符(Set Operators)
16、类型构造表达式(Type Constructor Operators)
17、查询表达式(Query Expressions)
深入Query Builder Methods查询语法~ObjectQuery方法
Distinct
Except
GroupBy
Intersect
OfType
OrderBy
Select
SelectValue
Skip
Top
Union
UnionAll
Where

Qurey Builder Methods查询语法

 

代码
1 using (NorthwindModel.NorthwindEntities nwEntity = new NorthwindModel.NorthwindEntities())
2 {
3 ObjectQuery<DbDataRecord> employees = nwEntity.Employees.Select("it.EmployeeID," +
4 "it.LastName," + "it.City," + "it.Country").Where("it.Country='USA'");
5
6 gvEmployees.DataSource = employees;
7 gvEmployees.DataBind();
8 }

 

 


三个Entity Fx好用的技巧
有效控制转换后的查询语法
拦截视图转换后的查询语法
以编译&快取增加查询效能
1、这里我们可以使用ToTraceString()方法来查看转换后的T-SQL语法。

2、使用预先编译的方式可以有效减少程序的执行时间。

代码
1 using(NorthwindModel.NorthwindEntities nwContext = new NorthwindModel.NorthwindEntities())
2 {
3 //建立Entity SQL查询字符串
4   string esql = @"Select Value Employees from NorthwindEntities.Employees";
5
6 //以ObjectQuery进行查询
7   ObjectQuery<NorthwindModel.Employees> employees = new ObjectQuery<NorthwindModel.Employees>(esql, nwContext, MergeOption.NoTracking);
8
9 gvEmployees.DataSource = employees;
10 gvEmployees.DataBind();
11 }

 

 

posted @ 2010-04-01 18:43  风影极光  阅读(398)  评论(0编辑  收藏  举报