Hi Viv,
I found this discussion
http://stackoverflow.com/questions/1119615/is-there-an-option-to-make-entity-framework-revert-empty-strings-to-nullI'll try adjusting the tt template using the suggested code. The only problem is that we're using Reverse POCO generator and not EF generator, so it may be not exactly clear how to adapt that code for our case.
>>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."
If it's not broken, fix it until it is.
My Blog