Assign an empty string to a property with a current value of nothing

In my EF4 EntityModel, I have an object named USERS. USERS have common fields UserName and Password string. If I do something like this:

Dim u as new USERS  
U.UserName = String.Empty

Then U.UserName is still nothing. But if I do something like this:

Dim u as new USERS   
u.UserName = "A"   
u.UserName = String.Empty

then U.UserName takes the value String.Empty as the value without any problems.

The reason is that EF4 generates a UserName property

Public Property UserName() As Global.System.String  
    Get  
        Return _UserName  
    End Get  
    Set  
        If (_UserName <> Value) Then    ‘Here is the key  
            OnUserNameChanging(value)  
            ReportPropertyChanging("UserName")  
            _UserName = StructuralObject.SetValidValue(value, false)  
            ReportPropertyChanged("UserName")  
                OnUserNameChanged()  
            End If  
        End Set  
    End Property  

My question is:

How can I handle this?

-, , ? , string.empty , , , , , . empty.string , "" .

#, vb.net, , - .

+3
2

? , nullable?

, EF T4 (VS ), setterter , , .

-

POCO, , ..

EntityObject, . T4 , T4, VS2010 , . , , . , , 523:

If (<#=code.FieldName(primitiveProperty)#> <> Value) Then

- , Object.Equals() , , . If, . T4, .

, , POCO .

, T4, Oleg Sych, http://www.olegsych.com/tag/t4/.

+2

, VB Nothing, - . , String.Equals.

If Not String.Equals(_UserName, Value) Then

Nothing "" ( String.Empty, ... ).

/EDIT: . , , .

+1

Source: https://habr.com/ru/post/1783633/


All Articles