ColumnAttribute.CanBeNull Proprietà

Definizione

Ottiene o imposta un valore che indica se una colonna può contenere valori null.

public:
 property bool CanBeNull { bool get(); void set(bool value); };
public bool CanBeNull { get; set; }
member this.CanBeNull : bool with get, set
Public Property CanBeNull As Boolean

Valore della proprietà

Valore predefinito = true.

Esempio

[Column(Storage="_LastName", DbType="NVarChar(20) NOT NULL", CanBeNull=false)]
public string LastName
{
    get
    {
        return this._LastName;
    }
    set
    {
        if ((this._LastName != value))
        {
            this.OnLastNameChanging(value);
            this.SendPropertyChanging();
            this._LastName = value;
            this.SendPropertyChanged("LastName");
            this.OnLastNameChanged();
        }
    }
}
<Column(Storage:="_LastName", DbType:="NVarChar(20) NOT NULL", CanBeNull:=false)>  _
Public Property LastName() As String
    Get
        Return Me._LastName
    End Get
    Set
        If ((Me._LastName = value)  _
                    = false) Then
            Me.OnLastNameChanging(value)
            Me.SendPropertyChanging
            Me._LastName = value
            Me.SendPropertyChanged("LastName")
            Me.OnLastNameChanged
        End If
    End Set
End Property

Commenti

Se si imposta questo valore su false, si presuppone che i dati nella colonna corrispondente siano non Null.

Nota

Questa proprietà viene duplicata dalla DbType proprietà per praticità. Il CreateDatabase metodo usa solo la DbType proprietà . Per questo motivo, è necessario specificare se una colonna può contenere valori Null anche nella DbType proprietà.

Si applica a