Invalid database property, but texbox still shows a red border when deleting content

Hey. I bind a WPF text box to an Entity Framework property as follows:

<TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" 
         Text="{Binding Path=MyEntityObject.SizeLower, Mode=TwoWay}" />

It binds the property perfectly, and when I change it, it saves the DB as expected. But if I delete the contents of the text field, I get a red error border around it. I don't have a validator in place, so I assume texbox complains that the value is not null. But actually this property in the database is null, so I can’t understand why this would be a mistake.

The system-defined definition of the EF property is as follows:

<EdmScalarPropertyAttribute(EntityKeyProperty:=false, IsNullable:=true)>
<DataMemberAttribute()>
Public Property SizeLower() As Nullable(Of Global.System.Int64)
    Get
        Return _SizeLower
    End Get
    Set
        OnSizeLowerChanging(value)
        ReportPropertyChanging("SizeLower")
        _SizeLower = StructuralObject.SetValidValue(value)
        ReportPropertyChanged("SizeLower")
        OnSizeLowerChanged()
    End Set
End Property

Private _SizeLower As Nullable(Of Global.System.Int64)

Is there something I am missing? I thought the binding system could determine if the property is null and allow null if so?

, ? .

.

===================================

, , . screencapture . , NULL , .

. , 10 ...! :

+3
1

TargetNullValue :

<TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" 
         Text="{Binding Path=MyEntityObject.SizeLower, 
         Mode=TwoWay, 
         TargetNullValue=''}" />

MyEntityObject.SizeLower string.empty , string.empty null .

+17

All Articles