none
bug in System.Nullable setter logic with Linq RRS feed

  • Question

  • When an item in the database can be null, linq correctly declares the item nullable.
    However in the setter logic it sets the PROPERTY to value instead of System.Nullable<T>().Value.

    Example Linq-generated code:  In this example, when the value is null it sets the entire property to null.  This causes the properly written logic "If TargetUnloadPort.HasValue" to throw an exception since the setter has destroyed the nullable object.

    [Column(Storage="_TargetUnloadPort", DbType="Int")]

    public System.Nullable<int> TargetUnloadPort

    {

    get

    {

    return this._TargetUnloadPort;

    }

    set

    {

    if ((this._TargetUnloadPort != value))

    {

    this._TargetUnloadPort = value;    <-- this should be set to: this._TargetUnloadPort.Value = value;

    }

    }

    }

     
    Monday, February 23, 2009 4:03 PM

Answers