首页 / 网页编程 / ASP.NET / Entity Framework学习初级篇4--Entity SQL
Entity Framework学习初级篇4--Entity SQL2010-02-05 博客园 ♂风车车.NetEntity SQl是ADO.NET实体框架提供的SQl类语言,用于支持实体数据模型(EDM)。Entity SQl可用于对象查询和使用EntityClient提供程序执行的查询。l 关键字Value关键字ESQl提供了SELECT VALUE子句以跳过隐式行构造。SELECT VALUE子句中只能指定一项。在使用这样的子句时,将不会对SELECT子句中的项构造行包装器,并且可生成所要形状的集合,例如:SELECT VALUE it FROM NorthwindEntities.Customers as itit关键字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 itl 参数参数是在esql之外定义的变量,每个参数都有名称和类型,参数名称在查询表达式中定义,并以@符号作为前缀。例如:Select VALUE c from NorthwindEntities.Customers as c where c.CustomerID=@customerIDl 聚合Enity SQL不支持 * ,所以esql不支持count(*),而是使用count(0),例如:Select count(0) from NorthwindEntities.Customersl 分页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 10l TOPSELECT子句可以在可选的ALl /DISTINCT 修饰符之后具有可选的TOP子子句。TOP子子句指定查询结果中将只返回第一组行。esql代码如下:Select top(10) c.CustomerID from NorthwindEntities.Customers as c order by c.CustomerIDl 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。