[索引页]
[源码下载]


再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL


作者:webabcd


介绍
以Northwind为示例数据库,ADO.NET Entity Framework之详解Entity SQL
  • Linq 方法上也可以使用 esql
  • 查询表达式
    • select, from, where, order by, group by, having
    • cross join, inner join, left outer join, right outer join, full outer join
    • case when then else end
  • 集合运算符
    • anyelement(expression) - 从集合中提取任意元素
    • except - 从左侧表达式的结果中删除其与右侧表达式结果中的相同项,并返回此结果
    • flatten(collection) - 将多个集合组成的集合转换为一个集合
    • intersect - 返回运算符两侧查询结果的相同项
    • [not] exists(expression) - 确定查询结果是否存在
    • [not] in {,} - 确定某值是否在某集合中
    • overlaps - 确定运算符两侧查询结果是否具有相同项
    • set(expression) - 移除重复项
    • union - 将运算符两侧查询结果连接成一个集合(移除重复项)
    • union all - 将运算符两侧查询结果连接成一个集合(包括重复项)
    • top(n) - 取前 n 条记录
  • 分页运算符
    • skip n - 需要跳过的项数,结合 order by 使用
    • limit n - 需要选择的项数,结合 order by 使用
  • 类型运算符
    • cast(expression as data_type) - 将表达式转换为另一种数据类型(使用 EntityCommand 执行查询,返回 EDM 类型;使用 ObjectQuery 执行查询,返回 CLR 类型)
    • oftype - 从查询表达式返回指定类型的对象集合,需 EDM 中继承关系的支持
    • is of - 确定表达式的类型是否为指定类型或指定类型的某个子类型,需 EDM 中继承关系的支持
    • treat - 将指定基类型的对象视为指定派生类型的对象,需 EDM 中继承关系的支持
  • 常用运算符
    • 算术运算符
      • +
      • -(减或负)
      • *
      • /
      • %
    • 比效运算符
      • >, >=, <, <=, <>, !=
      • is null, is not null
      • between and, not between and
      • like, not like
    • 通配符(应用于 like 和 not like)
      • % - 零个或零个以上的任意字符
      • _ - 任意单个字符
      • [] - 在指定范围 [a-f] 或集合 [abcdef] 中的任意单个字符
      • [^] - 不在指定范围 [^a-f] 或集合 [^abcdef] 中的任意单个字符
    • 逻辑运算符
      • and, &&
      • or, ||
      • not, !
    • 其他字符
      • -- - 注释
      • . - 成员访问
      • ; - 分行
      • + - 串联字符串
  • 函数
    • 函数 - 聚合函数
      • Avg(expression) - 非 null 的平均值
      • Count(expression) - 记录总数(Int64)
      • BigCount(expression) - 记录总数(Int32)
      • Max(expression) - 非 null 的最大值
      • Min(expression) - 非 null 的最小值
      • Sum(expression) - 非 null 的总和值
      • StDev(expression) - 非 null 的标准偏差值(相对于平均值的标准偏差)
    • 函数 - 数学函数
      • Abs(value) - 取绝对值
      • Ceiling(value) - 取不小于参数的最小整数
      • Floor(value) - 取不大于参数的最大整数
      • Round(value) - 取参数的整数部分
    • 函数 - 字符串函数
      • Left(string, length) - 从左侧开始,取 string 的前 length 个字符
      • Right( tring, length) - 从右侧开始,取 string 的前 length 个字符
      • LTrim(string) - 去掉 string 的左侧的空白
      • RTrim(string) - 去掉 string 的右侧的空白
      • Trim(string) - 去掉 string 的两侧的空白
      • ToLower(string) - 将 string 全部转换为小写
      • ToUpper(string) - 将 string 全部转换为大写
      • Concat(string1, string2) - 串联 string1 和 string2
      • Replace(string1, string2, string3) - 将 string1 中的所有 string2 都替换为 string3
      • Reverse(string) - 取 string 的反序
      • Substring(string, start, length) - 从 string 的 start 位置开始取 length 个字符,索引从 1 开始
      • IndexOf(string1, string2) - string1 在 string2 中的位置,索引从 1 开始,若找不到则返回 0
    • 函数 - 日期和时间函数
      • Year(expression) - 取时间的年的部分
      • Month(expression) - 取时间的月的部分
      • Day(expression) - 取时间的日的部分
      • Hour(expression) - 取时间的时的部分
      • Minute(expression) - 取时间的分的部分
      • Second(expression) - 取时间的秒的部分
      • Millisecond(expression) - 取时间的毫秒的部分(0 - 999)
      • CurrentDateTime() - 取服务器的当前时间
      • CurrentUtcDateTime() - 取服务器的 UTC 当前时间
      • CurrentDateTimeOffset() - 返回值类型为 DateTimeOffset , 取当前时间及相对于 UTC 时间的差值
    • 函数 - 按 位 运算的函数
      • BitWiseAnd(value1, value2) - 取 value1 和 value2 的位与结果
      • BitWiseOr(value1, value2) - 取 value1 和 value2 的位或结果
      • BitWiseXor(value1, value2) - 取 value1 和 value2 的位异或结果
      • BitWiseNot(value) - 取 value 的位求反结果
    • 函数 - 其它函数
      • NewGuid() - 返回新生成的 GUID
  • 不常用运算符
    • row, multiset, createref, deref, key, ref, navigate


示例
EntitySQL.aspx.cs
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQLusing System;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Collections.Generic;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Linq;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Web;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Web.UI;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Web.UI.WebControls;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Data.Objects;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Data.Objects.DataClasses;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using System.Data.Common;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
using VS2008SP1.Business;
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
再接再厉VS 2008 sp1 + .NET 3.5 sp1(6) - Entity Framework(实体框架)之Entity SQL
public partial class EntityFramework_EntitySQL : System.Web.UI.Page


OK
[源码下载]

相关文章: