CLR 方法至规范函数映射

实体框架提供了一组规范函数(如字符串操作函数和数学函数),这些函数可以实现很多数据库系统通用的功能。 这使开发人员可以面向广泛的数据库系统。 通过查询技术(如 LINQ to Entities)调用时,这些规范函数将转换为要使用的提供程序的相应正确存储区函数。 这样,可以用一种数据源通用的形式表示函数调用,从而在数据源之间提供一致的查询体验。 如果操作数是数值类型,则按位 AND、OR、NOT 和 XOR 运算符也将映射到规范函数。 对于布尔操作数,按位 AND、OR、NOT 和 XOR 运算符将计算其操作数的逻辑 AND、OR、NOT 和 XOR 运算。 有关详细信息,请参阅规范函数

对于 LINQ 方案,对实体框架执行的查询涉及通过规范函数将某些 CLR 方法映射到基础数据源的方法。 LINQ to Entities 查询中未显式映射到规范函数的任何方法调用都会导致引发运行时 NotSupportedException 异常。

System.String 方法(静态)映射

System.String 方法(静态) 规范函数
System.String Concat(String、Stringstr0str1 Concat(str0str1
System.String Concat(String str0、String str1、String str2 Concat(Concat(str0str1), str2
System.String Concat(String、String、Stringstr1、Stringstr03str2str0 Concat(Concat(Concat(str0str1), str2str3
布尔型等值(String a, String b) = 运算符
布尔 IsNullOrEmpty(字符串 value (IsNull(value))或者Length(value)= 0
布尔op_Equality(字符串、字符串ab = 运算符
Boolean op_Inequality(String a , String b) != 运算符
Microsoft.VisualBasic.Strings.Trim(String str Trim(str
Microsoft.VisualBasic.Strings.LTrim(String str Ltrim(str
Microsoft.VisualBasic.Strings.RTrim(String str Rtrim(str
Microsoft.VisualBasic.Strings.Len(String expression Length(expression
Microsoft.VisualBasic.Strings.Left(String str、Int32 Length Left(strLength
Microsoft.VisualBasic.Strings.Mid(Stringstr、Int32Start、Int32Length Substring(strStartLength
Microsoft.VisualBasic.Strings.Right(String,Int32strLength Right(strLength
Microsoft.VisualBasic.Strings.UCase(String Value ToUpper(Value
Microsoft.VisualBasic.Strings.LCase(字符串值) ToLower(Value

System.String 方法(实例)映射

System.String 方法(实例) 规范函数 备注
布尔包含(字符串 value this LIKE '%value%' 如果 value 不是常量,则它映射到 IndexOf(this, value) > 0
布尔值 EndsWith(字符串 value this LIKE '%value' 如果 value 不是常量,则它映射到 Right(this, length(value)) = value
Boolean StartsWith(String value this LIKE 'value%' 如果 value 不是常量,则它映射到 IndexOf(this, value) = 1。
长度 Length(this
Int32 IndexOf(字符串 value IndexOf(thisvalue) - 1
System.String Insert(Int32 startIndex, String value Concat(Concat(Substring(this, 1, startIndex), value子字符串(thisstartIndex+1, Length(this) - startIndex
System.String Remove(Int32 startIndex Substring(this、1、 startIndex
System.String Remove(Int32 startIndex、Int32 count Concat(Substring(this, 1, startIndex), Substring(thisstartIndex + count +1, Length(this) - (startIndex + count)) Remove(startIndex, count) 仅在 count 是大于或等于 0 的整数时才受支持。
System.String Replace(字符串 oldValue、字符串 newValue Replace(thisoldValuenewValue
System.String Substring(Int32 startIndex Substring(thisstartIndex +1, Length(this) - startIndex
System.String Substring(Int32 startIndex、Int32 length Substring(thisstartIndex +1、 length
System.String ToLower() ToLower(this
System.String ToUpper() ToUpper(this
System.String Trim() Trim(this
System.String TrimEnd(Char[] ) trimChars RTrim(this
System.String TrimStart(Char[]trimChars LTrim(this
布尔等值(字符串 value = 运算符

System.DateTime 方法(静态)映射

System.DateTime 方法(静态) 规范函数 备注
布尔等值(DateTime、DateTimet1t2 = 运算符
System.DateTime.Now CurrentDateTime()
System.DateTime.UtcNow CurrentUtcDateTime()
布尔op_Equality(DateTime、DateTimed1d2 = 运算符
布尔op_GreaterThan(DateTime、DateTimet1t2 > 运算符
布尔op_GreaterThanOrEqual(DateTime、DateTimet1t2 >= 运算符
布尔op_Inequality(DateTime、DateTimet1t2 != 运算符
布尔op_LessThan(DateTime、DateTimet1t2 < 运算符
布尔op_LessThanOrEqual(DateTime、DateTimet1t2 <= 运算符
Microsoft.VisualBasic.DateAndTime.DatePart( _

ByVal Interval As DateInterval, _

ByVal DateValue As DateTime, _

可选 ByVal FirstDayOfWeekValue As FirstDayOfWeek = VbSunday, _

可选 ByVal FirstWeekOfYearValue As FirstWeekOfYear = VbFirstJan1 _

) 为整数
有关详细信息,请参见“DatePart 函数”部分。
Microsoft.VisualBasic.DateAndTime.Now CurrentDateTime()
Microsoft.VisualBasic.DateAndTime.Year(DateTime TimeValue 年份()
Microsoft.VisualBasic.DateAndTime.Month(DateTime TimeValue Month()
Microsoft.VisualBasic.DateAndTime.Day(DateTime TimeValue Day()
Microsoft.VisualBasic.DateAndTime.Hour(DateTime TimeValue Hour()
Microsoft.VisualBasic.DateAndTime.Minute(DateTime TimeValue Minute()
Microsoft.VisualBasic.DateAndTime.Second(DateTime TimeValue Second()

System.DateTime 方法(实例)映射

System.DateTime 方法(实例) 规范函数
布尔等值(DateTime value = 运算符
Day(this
小时 Hour(this
毫秒 毫秒(this
分钟 Minute(this
月份 Month(this
第二个 Second(this
年份 Year(this

System.DateTimeOffset 方法(实例)映射

针对列出的属性上 get 方法显示的映射。

System.DateTimeOffset 方法(实例) 规范函数 备注
Day(this 对 SQL Server 2005 不支持。
小时 Hour(this 对 SQL Server 2005 不支持。
毫秒 毫秒(this 对 SQL Server 2005 不支持。
分钟 Minute(this 对 SQL Server 2005 不支持。
月份 Month(this 对 SQL Server 2005 不支持。
第二个 Second(this 对 SQL Server 2005 不支持。
年份 Year(this 对 SQL Server 2005 不支持。

备注

如果比较的 Equals 对象相等,则 true 方法返回 DateTimeOffset;否则返回 falseCompareTo 方法返回 0、1 或 -1,分别取决于比较的 DateTimeOffset 对象是相等、大于还是小于。

System.DateTimeOffset

针对列出的属性上 get 方法显示的映射。

System.DateTimeOffset 规范函数 备注
System.DateTimeOffset.Now() CurrentDateTimeOffset() 对 SQL Server 2005 不支持。

System.TimeSpan

针对列出的属性上 get 方法显示的映射。

System.TimeSpan 方法(实例) 规范函数 备注
小时 Hour(this 对 SQL Server 2005 不支持。
毫秒 毫秒(this 对 SQL Server 2005 不支持。
分钟数 Minute(this 对 SQL Server 2005 不支持。
Second(this 对 SQL Server 2005 不支持。

备注

如果比较的 Equals 对象相等,则 true 方法返回 TimeSpan;否则返回 falseCompareTo 方法返回 0、1 或 -1,分别取决于比较的 TimeSpan 对象是相等、大于还是小于。

DatePart

DatePart 函数根据 Interval 的值映射到几个不同规范函数中的一个。 下表列出了受支持的 Interval 值的规范函数映射。

Interval 值 规范函数
DateInterval.Year 年份()
DateInterval.Month Month()
DateInterval.Day Day()
DateInterval.Hour Hour()
DateInterval.Minute Minute()
DateInterval.Second Second()

数学函数映射

CLR 方法 规范函数
System.Decimal.Ceiling(十进制 d 上限(d
System.Decimal.Floor(十进制 d 楼层(d
System.Decimal.Round(十进制 d Round(d
System.Math.Ceiling(Decimal d 上限(d
System.Math.Floor(十进制 d 楼层(d
System.Math.Round(十进制 d Round(d
System.Math.Ceiling(双 a 上限(a
System.Math.Floor(双 a 楼层(a
System.Math.Round(Double a Round(a
System.Math.Round(Double 值, Int16 位数) Round(值, 位数)
System.Math.Round(Double 值, Int32 位数) Round(值, 位数)
System.Math.Round(Decimal 值, Int16 位数) Round(值, 位数)
System.Math.Round(Decimal 值, Int32, 位数) Round(值, 位数)
System.Math.Abs(Int16 值) Abs(value)
System.Math.Abs(Int32 值) Abs(value)
System.Math.Abs(Int64 值) Abs(value)
System.Math.Abs(Byte 值) Abs(value)
System.Math.Abs(Single 值) Abs(value)
System.Math.Abs(Double 值) Abs(value)
System.Math.Abs(Decimal 值) Abs(value)
System.Math.Truncate(Double 值, Int16 位数) Truncate(值, 位数)
System.Math.Truncate(Double 值, Int32 位数) Truncate(值, 位数)
System.Math.Truncate(Decimal 值, Int16 位数) Truncate(值, 位数)
System.Math.Truncate(Decimal 值, Int32 位数) Truncate(值, 位数)
System.Math.Power(Int32 值, Int64 指数) Power(值, 指数)
System.Math.Power(Int32 值, Double 指数) Power(值, 指数)
System.Math.Power(Int32 值, Decimal 指数) Power(值, 指数)
System.Math.Power(Int64 值, Int64 指数) Power(值, 指数)
System.Math.Power(Int64 值, Double 指数) Power(值, 指数)
System.Math.Power(Int64 值, Decimal 指数) Power(值, 指数)
System.Math.Power(Double 值, Int64 指数) Power(值, 指数)
System.Math.Power(Double 值, Double 指数) Power(值, 指数)
System.Math.Power(Double 值, Decimal 指数) Power(值, 指数)
System.Math.Power(Decimal 值, Int64 指数) Power(值, 指数)
System.Math.Power(Decimal 值, Double 指数) Power(值, 指数)
System.Math.Power(Decimal 值, Decimal 指数) Power(值, 指数)

位运算符映射

位运算符 非布尔操作数的规范函数 布尔操作数的规范函数
位 AND 运算符 BitWiseAnd op1 AND op2
位 OR 运算符 BitWiseOr op1 或 op2
位 NOT 运算符 BitWiseNot NOT(op)
位 XOR 运算符 BitWiseXor ((op1 AND NOT(op2)) 或 (NOT(op1) AND op2)

其他映射

方法 规范函数
Guid.NewGuid() NewGuid()

请参阅