共用方式為


標準函式的對應 CLR 方法

Entity Framework 提供一組標準函式,可實作在許多資料庫系統常見的功能,例如字串操作和數學函式。 這樣就可以讓開發人員以廣泛的資料庫系統為相標。 從某種查詢技術 (例如 LINQ to Entities) 呼叫時,這些標準函式會轉譯成所使用之提供者的正確對應存放函式。 這樣就可以利用跨資料來源的通用形式來表示函式引動過程,在不同的資料來源提供一致的查詢體驗。 如果運算元為數值型別,位元運算 AND、OR,、NOT 和 XOR 運算子也是對應到這些標準函式。 若為布林運算元,位元運算 AND、OR、NOT 和 XOR 運算子會計算這些運算元的邏輯 AND、OR、NOT 和 XOR 運算。 如需詳細資訊,請參閱標準函式

就 LINQ 案例而言,針對 Entity Framework 的查詢會透過標準函式將某些 CLR 方法對應到基礎資料來源。 在 LINQ to Entities 查詢中,不是明確對應到標準函式的任何方法呼叫,將會導致擲回執行階段 NotSupportedException 例外狀況 (Exception)。

System.String 方法 (靜態) 對應

System.String 方法 (靜態) 標準函式
System.String Concat(String str0,String str1 Concat(str0str1
System.String Concat(String str0、 String str1、 String str2 Concat(Concat〈c0 /〉,〈c1 /〉),〈c2 /〉
System.String Concat(String str0、String str1、String str2、String str03) Concat(Concat(Concat(str0str1),str2),str3
布林值等號(字串 a, 字串 b = 運算子
布林型 IsNullOrEmpty(String value (IsNull(value)) OR Length(value) = 0
布林運算op_Equality(字串 a, 字串 b) = 運算子
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 長度(expression
Microsoft.VisualBasic.Strings.Left(String str,Int32 Length) Left(strLength
Microsoft.VisualBasic.Strings.Mid(String str, Int32 Start, Int32 Length Substring(strStartLength
Microsoft.VisualBasic.Strings.Right(String str,Int32 Length Right(strLength
Microsoft.VisualBasic.Strings.UCase(String Value ToUpper(Value
Microsoft.VisualBasic.Strings.LCase(字串值) ToLower(Value

System.String 方法 (執行個體) 對應

System.String 方法 (執行個體) 標準函式 備註
布林值 Contains(字串 value this LIKE '%%value ' value 不是一個常數,則其會對應至 IndexOf(thisvalue) > 0
布林值 EndWith(字串 value this LIKE '%value' 如果 value 不是一個常數,則這會對應至 Right(this, length(value)) = value
布林值型別的 StartsWith(字串 value this 類似於 'value%' 如果 value 不是一個常數,則這會對應至 IndexOf(this, value) = 1。
長度 長度(this
Int32 IndexOf(字串 value IndexOf(thisvalue) - 1
System.String Insert(Int32 startIndex, String value Concat(Concat(Substring(this, 1, startIndex), value子字串(thisstartIndex+1, 長度(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 + +1, Length(countthis) - (startIndex + count)) ) 只有當 startIndex 是大於或等於 0 的整數時,才支援 Remove(count, count)。
System.String Replace(String oldValue,String 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
Boolean 相等(String value) = 運算子

System.DateTime 方法 (靜態) 對應

System.DateTime 方法 (靜態) 標準函式 備註
布林值 Equals(DateTime t1、 DateTime t2 = 運算子
System.DateTime.Now CurrentDateTime()
System.DateTime.UtcNow CurrentUtcDateTime()
布林值op_Equality(DateTime、 DateTime d1d2 = 運算子
布林值op_GreaterThan(DateTime, DateTime t1t2 > 運算子
布林值op_GreaterThanOrEqual(DateTime, DateTime t1t2 >= 運算子
布林運算_不相等(DateTime t1, DateTime t2) != 運算子
布林值 op_LessThan(DateTime t1, DateTime t2) < 運算子
布林op_LessThanOrEqual(DateTime t1, DateTime t2) <= 運算子
Microsoft.VisualBasic.DateAndTime.DatePart( _

ByVal Interval As DateInterval, _

ByVal DateValue As DateTime,_

Optional 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 小時()
Microsoft.VisualBasic.DateAndTime.Minute(DateTime TimeValue 分鐘()
Microsoft.VisualBasic.DateAndTime.Second(DateTime TimeValue 第二()

System.DateTime 方法 (執行個體) 對應

System.DateTime 方法 (執行個體) 標準函式
Boolean Equals(DateTime value = 運算子
Day(this
小時 小時(this
毫秒 毫秒(this
分鐘 分鐘(this
月份(this
第二秒 第二(this
年(this

System.DateTimeOffset 方法 (執行個體) 對應

為列出之屬性上的 get 方法顯示的對應。

System.DateTimeOffset 方法 (執行個體) 標準函式 備註
Day(this 對 SQL Server 2005 不支援。
小時 小時(this 對 SQL Server 2005 不支援。
毫秒 毫秒(this 對 SQL Server 2005 不支援。
分鐘 分鐘(this 對 SQL Server 2005 不支援。
月份(this 對 SQL Server 2005 不支援。
第二秒 第二(this 對 SQL Server 2005 不支援。
年(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 方法 (執行個體) 標準函式 備註
小時 小時(this 對 SQL Server 2005 不支援。
毫秒 毫秒(this 對 SQL Server 2005 不支援。
分鐘 分鐘(this 對 SQL Server 2005 不支援。
第二(this 對 SQL Server 2005 不支援。

注意

如果比較的 Equals 物件相等,true 方法會傳回 TimeSpan;否則會傳回 falseCompareTo 方法會傳回 0、1 或 -1,需視比較的 TimeSpan 物件是否分別為相等、大於或小於而定。

DatePart 函式

DatePart 函式會對應到幾個不同標準函式的其中一個,根據 Interval 的值而定。 下表顯示支援之 Interval 值的標準函式對應:

間隔值 標準函式
日期區間.年份 年()
日期間距.月 Month()
日期間隔.天 Day()
日期間隔.小時 小時()
DateInterval.Minute 分鐘()
DateInterval.Second 第二()

數學函式對應

CLR 方法 標準函式
System.Decimal.Ceiling(十進制 d 天花板(d
System.Decimal.Floor(十進制 d 地板(d
System.Decimal.Round(十進制 d 圓(d
System.Math.Ceiling(十進制 d 天花板(d
System.Math.Floor(十進制 d 地板(d
System.Math.Round(十進制 d 圓(d
System.Math.Ceiling(雙 a 天花板(a
System.Math.Floor(Double a 地板(a
System.Math.Round(Double a 圓(a
System.Math.Round(雙精度浮點數值、Int16 數字) Round(值、數字)
System.Math.Round(雙精度浮點數值、Int32 數字) Round(值、數字)
System.Math.Round(十進位值、Int16 數字) Round(值、數字)
System.Math.Round(十進位值、Int32 數字) Round(值、數字)
System.Math.Abs(Int16 值) Abs(value)
System.Math.Abs(Int32 值) Abs(value)
System.Math.Abs(Int64 值) Abs(value)
System.Math.Abs(位元組值) Abs(value)
System.Math.Abs(單一值) Abs(value)
System.Math.Abs(雙精度浮點數值) Abs(value)
System.Math.Abs(十進位值) Abs(value)
System.Math.Truncate(雙精度浮點數值、Int16 數字) Truncate(值、數字)
System.Math.Truncate(雙精度浮點數值、Int32 數字) Truncate(值、數字)
System.Math.Truncate(十進位值、Int16 數字) Truncate(值、數字)
System.Math.Truncate(十進位值、Int32 數字) Truncate(值、數字)
System.Math.Power(Int32 值、Int64 指數) Power(值、指數)
System.Math.Power(Int32 值、雙精度浮點指數) Power(值、指數)
System.Math.Power(Int32 值、十進位指數) Power(值、指數)
System.Math.Power(Int64 值、Int64 指數) Power(值、指數)
System.Math.Power(Int64 值、雙精度浮點指數) Power(值、指數)
System.Math.Power(Int64 值、十進位指數) Power(值、指數)
System.Math.Power(雙精度浮點數值、Int64 指數) Power(值、指數)
System.Math.Power(雙精度浮點數值、雙精度浮點指數) Power(值、指數)
System.Math.Power(雙精度浮點數值、十進位指數) Power(值、指數)
System.Math.Power(十進位值、Int64 指數) Power(值、指數)
System.Math.Power(十進位值、雙精度浮點指數) Power(值、指數)
System.Math.Power(十進位值、十進位指數) Power(值、指數)

位元運算子對應

位元運算子 非布林運算元的標準函式 布林運算元的標準函式
位元 AND 運算子 BitWiseAnd op1 和 op2
位元 OR 運算子 BitWiseOr 選項1 或 選項2
位元 NOT 運算子 BitWiseNot 非(op)
位元 XOR 運算子 BitWiseXor ((op1 AND NOT(op2)) OR (NOT(op1) AND op2))

其他對應

方法 標準函式
Guid.NewGuid() NewGuid()

另請參閱