ColumnAttribute.Expression Proprietà

Definizione

Ottiene o imposta un valore che indica se una colonna è una colonna calcolata in un database.

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

Valore della proprietà

Impostazione predefinita = vuoto.

Esempio

[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

Commenti

Utilizzare questa proprietà quando si usa CreateDatabase per definire una colonna come contenente valori calcolati.

Ad esempio, se si vuole creare una colonna definita in SQL come InventoryVal AS UnitPrice * UnitsInStock, usare la stringa di espressione seguente: "UnitPrice * UnitsInStock".

Nota

LINQ to SQL non supporta le colonne calcolate come chiavi primarie.

Si applica a