SqlFacetAttribute 類別

定義

對使用者定義型別 (UDT) 的傳回結果加註可在 Transact-SQL 中使用的其他資訊。

public ref class SqlFacetAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, AllowMultiple=false, Inherited=false)]
public class SqlFacetAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, AllowMultiple=false, Inherited=false)>]
type SqlFacetAttribute = class
    inherit Attribute
Public Class SqlFacetAttribute
Inherits Attribute
繼承
SqlFacetAttribute
屬性

備註

SqlFacetAttribute 只能在非 void 傳回值上指定。

SqlFacetAttribute 只用來衍生傳回型別的相關信息,而且不適合做為類型中可儲存之專案的條件約束規格。 因此,如果欄位具有 SqlFacetAttribute ,表示其大小為 2 個字元,則欄位存取表達式的 SQL Server 類型大小為 2,但此 Facet 不會限制欄位中的工作分派。

下表會擷取特定欄位類型各種屬性的有效值矩陣。 在此數據表中,“Y” 表示屬性有效,而 “N” 表示屬性無效。

指定的 SqlFacetAttribute 必須與欄位類型相容。 如果屬性無效,如果使用者指定屬性的非預設值,則類型註冊會報告錯誤。 和 Scale 屬性的Precision最大值為 38。 MaxSize針對 屬性,值應介於二進位和非 Unicode 數據的 1-8000 範圍內、Unicode 數據的 1-4000 或 -1。 所有其他值都無效。

類型 IsFixedLength MaxSize 精確度 調整 IsNullable
SqlBoolean N N N N
SqlByte N N N N
SqlInt16 N N N N
SqlInt32 N N N N
SqlInt64 N N N N
SqlSingle N N N N
SqlDouble N N N N
SqlDateTime N N N N
SqlMoney N N N N
SqlGuid N N N N
SqlDecimal N N Y Y Y
SqlString Y Y N N Y
SqlBinary Y Y N N
SqlXml N N N N Y
SqlBytes Y Y N N Y
SqlChars Y Y N N Y
內嵌UDT N N N N Y
String Y Y N N Y
Byte[] Y Y N N Y
Char[] Y Y N N
DateTime N N N Y1 N
Decimal N N Y Y Y

(1) 在 DateTime 類型上指定小數位數會導致值傳回至 Transact-SQL 做為具有指定尺規的 DateTime2 類型。

建構函式

SqlFacetAttribute()

使用者定義型別 (UDT) 傳回型別上的選擇性屬性,用於對傳回結果加註可在 Transact-SQL 中使用的其他資訊。

屬性

IsFixedLength

指出使用者定義型別的傳回型別是否為固定長度。

IsNullable

指出使用者定義型別的傳回型別是否可為 null

MaxSize

使用者定義型別之基礎欄位型別的最大大小,以邏輯單位 (Logical Unit) 計算。

Precision

使用者定義型別之傳回型別的精確度。

Scale

使用者定義型別之傳回型別的小數點位數。

適用於