`

Entity Framework分页

    博客分类:
  • c#
阅读更多

ntity Framework学习初级篇4--Entity SQL

时间:2010-02-05 博客园 ♂风车车.Net

Entity SQl是ADO.NET实体框架提供的SQl类语言,用于支持实体数据模型(EDM)。Entity SQl可用于对象查询和使用EntityClient提供程序执行的查询。

l 关键字

Value关键字

ESQl提供了SELECT VALUE子句以跳过隐式行构造。SELECT VALUE子句中只能指定一项。在使用这样的子句时,将不会对SELECT子句中的项构造行包装器,并且可生成所要形状的集合,例如:SELECT VALUE it FROM NorthwindEntities.Customers as it

it关键字

it 出现在ESQl中, 查询对象的别名默认值 "it" 改成其他字符串,例如:

"SELECT VALUE it FROM NorthwindEntities.Customers as it " 。

l 注释:

Entity SQl 查询可以包含注释。注释行以两个短划线(--) 开头。

"SELECT VALUE it FROM NorthwindEntities.Customers as it  -- this a comment "

l Select查询

例如:

SELECT VALUE it FROM NorthwindEntities.Customers as it

l 参数

参数是在esql之外定义的变量,每个参数都有名称和类型,参数名称在查询表达式中定义,并以@符号作为前缀。例如:

Select VALUE c from NorthwindEntities.Customers as c where c.CustomerID=@customerID

l 聚合

Enity SQL不支持 * ,所以esql不支持count(*),而是使用count(0),例如:

Select count(0) from NorthwindEntities.Customers

l 分页SKIP/LIMIT

可以通过在ORDER BY子句中使用SKIP 和 LIMIT子子句执行物理分页。若要以确定的方式执行物理分页,应使用SKIP 和 LIMIT。如果您只是希望以非确定的方式限制结果中的行数,则应使用TOP。TOP 和 SKIP/LIMIT是互斥的

使用SKIP/LIMIT分页,esql代码如下:

Select value c from NorthwindEntities.Customers as c order by c.CustomerID skip 0 limit 10

l TOP

SELECT子句可以在可选的ALl /DISTINCT 修饰符之后具有可选的TOP子子句。TOP子子句指定查询结果中将只返回第一组行。esql代码如下:

Select top(10) c.CustomerID from NorthwindEntities.Customers as c order by c.CustomerID

l NULL处理

Null文本与Entity SQl类型系统中的任何类型都兼容,可以使用cast进行类型转换,例如:

select cast(c.region as string) from NorthwindEntities.Customers as c order by c.CustomerID limit 10

其中, Nvarchar等可以成string,数字类型可以转成int32,其他的类型转换类似。如果无法完成转换,则将报异常。还有可以处理的方法有treat。

 

 

本文转自:http://soft-app.iteye.com/blog/1360627

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics