Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any setting to convert null strings to empty automatical
Message
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01608410
Message ID:
01608713
Vues:
36
Why would you want to?

null for strings is a perfectly acceptable value since most operations with null strings (like concatenation and various assignments) pretty work the same as "". It's not like FoxPro where NULL breaks other common operations.

That plus check for string.IsNullOrEmpty() which is pretty standard for string empty checks.

Generally ""/string.Empty shouldn't be used unless there's a very specific reason for it.

+++ Rick ---



>Hi everybody,
>
>Do you know if there is any way (or setting) to automatically convert null strings into "" strings?
>
>In our database all character columns are not nullable. We have default values set to be empty string.
>
>So, now using Entity Framework we have the following
>
>public string UserCode { get; set; }
>
>and also
>
>
>Property(x => x.UserCode).IsRequired().HasColumnName("user_code").IsUnicode(false).HasMaxLength(25);
>
>If we remove the IsRequired and attempt to create a new row, then we get the error with inner exception such as
>Cannot insert the value NULL into column 'user_code', table 'SiriusSQL_SysManager.dbo.specials'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated.
>
>So, I am wondering if there is some relatively simple generic solution to produce empty string instead of the null.
>
>The classes are auto-generated, so this change needs to be auto-generated as well.
>
>Thanks a lot in advance.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform