Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3661518
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:18:50+00:00 2026-05-19T01:18:50+00:00

In my EF4 EntityModel I have an entity named USERS. USERS have the common

  • 0

In my EF4 EntityModel I have an entity named USERS. USERS have the common UserName and Password string fields. 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 String.Empty as value without problem.

The reason is the way that EF4 generates the 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 deal with it?

Is there something I can do to avoid this behavior? I do not want to make two assignations every time I want to set string.empty to a property with a nothing value, and I do not want to remember that I must do it in this way every time, because I’m pretty sure that I will forget it and then I will introduce bugs in the code. I just want to assign the empty.string value to a property and the property take “” as value.

As I come from C# and I’m a newbie in vb.net, I really hope that I’was missing something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:18:51+00:00Added an answer on May 19, 2026 at 1:18 am

    Do you definitely want to assign an empty string instead of an empty value? If not you could just set the property to be nullable?

    Either way you can manipulate the code that EF generates by using T4 templates (VS calls them Code Generators), so you could change the property setter implementation to whatever you wanted by doing that.

    Edit – adding a bit more detail

    If you use the POCO generator, you get plain properties, i.e. no property changed etc

    If you use the EntityObject generator, it basically lets you edit the generation you currently have. If you use a T4 add in for visual studio you get syntax highlighting on the T4, there are some free ones available in the VS2010 add ins which are very good. You basically have code that generates code there, which you can tweak. the line you flagged is on line 523:

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

    You could try and do something funky based on type, or you could just revert to using Object.Equals(), or whatever else you want, instead of this line. Or you could remove the If section entirely but that might have other consequences. When you save the T4 template, it’ll update all the generated code for you.

    Depending what you are actually doing, the POCO template might cure your problem.

    BTW if you want more on T4, visit Oleg Sych’s blog, http://www.olegsych.com/tag/t4/ .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.