Share via


ColumnAttribute.Expression 屬性

定義

取得或設定資料行是否為資料庫中的計算資料行。

public:
 property System::String ^ Expression { System::String ^ get(); void set(System::String ^ value); };
public string Expression { get; set; }
member this.Expression : string with get, set
Public Property Expression As String

屬性值

預設 = 空白。

範例

[Column(Storage="_UnitPrice", DbType="Money",Expression="UnitPrice + 1.00")]
public System.Nullable<decimal> UnitPrice
{
    get
    {
        return this._UnitPrice;
    }
    set
    {
        if ((this._UnitPrice != value))
        {
            this.OnUnitPriceChanging(value);
            this.SendPropertyChanging();
            this._UnitPrice = value;
            this.SendPropertyChanged("UnitPrice");
            this.OnUnitPriceChanged();
        }
    }
}
   <Column(Storage:="_UnitPrice", DbType:="Money NOT NULL", Expression:="UnitPrice + 1.00")> _
Public Property UnitPrice() As Decimal
       Get
           Return Me._UnitPrice
       End Get
       Set(ByVal value As Decimal)
           If ((Me._UnitPrice = Value) _
              = False) Then
               Me.OnUnitPriceChanging(Value)
               Me.SendPropertyChanging()
               Me._UnitPrice = Value
               Me.SendPropertyChanged("UnitPrice")
               Me.OnUnitPriceChanged()
           End If
       End Set
   End Property

備註

當您使用 CreateDatabase 將資料行定義為包含計算值時,請使用這個屬性。

例如,如果您想要在 SQL InventoryVal AS UnitPrice * UnitsInStock中建立定義為的數據行,請使用下列 表示式 字串: "UnitPrice * UnitsInStock"

注意

LINQ to SQL 不支援以計算資料行作為主索引鍵。

適用於