1
Vote

Dataform converts null string to String.Empty

description

Dataform 4.0.5.0
 
If I got readOnly string field that contains null, dataform tries to set this value String.Empty. As this field is readOnly it fails validation. I cannot edit this entry.
 
Currently the problem is that because of this in my database some fields are string.Empty some NULL. And I cannot use this workaround: http://blog.ondrejsv.com/post/Silverlight-DataForme28099s-autogenerated-fields-send-empty-strings-to-database.aspx

comments

Aurimas86 wrote Mar 29, 2012 at 8:32 AM

Workaround:

On AutoGeneratingField add converter to field binding

public class DataFormStringEmptyBugConverter : IValueConverter
{
    private object originalValue;

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        originalValue = value;
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (targetType != typeof(string))
        {
            return value;
        }
        if (string.IsNullOrEmpty((string)value))
        {
            return originalValue;
        }
        return value;
    }
}

Aurimas86 wrote Apr 6, 2012 at 12:01 PM

For workaround line:
if (string.IsNullOrEmpty((string)value))
should be replaced with
if (string.IsNullOrEmpty((string)value) && string.IsNullOrEmpty((string)originalValue))