Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any setting to convert null strings to empty automatical
Message
From
29/09/2014 12:02:11
 
General information
Forum:
ASP.NET
Category:
Entity Framework
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01608410
Message ID:
01608465
Views:
29
>>>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.
>>
>>See ConvertEmptyStringToNull : http://msdn.microsoft.com/en-us/library/vstudio/ms366709(v=vs.100).aspx
>>
>>" If the ConvertEmptyStringToNull property is false for an object, and the value of the object is an empty string, an empty string is passed to the data source as the object value."
>
>Hi Viv,
>
>Looks like this property is opposite of what I need. I want NULL strings to be treated as empty strings.

??

Did I misunderstand your explanation. I thought you said:
(a) SQL database does not allow Null strings ?
(b) You were having a problem trying to save an empty C# string.
If so then ConvertEmptyStringToNull(false) sounds like what you need.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform