I am calling
Csla.Data.DataMapper.Map(e.Values, obj)
in XYZ_UpdateObject.
This works fine when I use a DetailsView to map an empty TextBox to a Nullable (of Int32), but not when I use a FormView. The problem occurs in SetPropertyValue because when using a DetailsView the value from the empty TextBox comes through as Nothing, whereas it comes through as "" {String} from a FormView.
SetPropertyValue could easily check for this by changing
' types don't match, try to coerce types If pType.Equals(GetType(Guid)) ThenpropertyInfo.SetValue(target,
New Guid(value.ToString), Nothing)to
' types don't match, try to coerce types If vType.Equals(GetType(String)) AndAlso String.IsNullOrEmpty(value.ToString) ThenpropertyInfo.SetValue(target,
Nothing, Nothing) ElseIf pType.Equals(GetType(Guid)) ThenpropertyInfo.SetValue(target,
New Guid(value.ToString), Nothing)Is this something that should be fixed.
Rocky,
Yes that would be more elegant.
Also, on the lines at the beginning of the procedure:
If value Is Nothing Then
propertyInfo.SetValue(target, value, Nothing)
It might be worth doing the same check for pType is a Nullable<T> before try to set the target to nothing: Although that would also mean moving the line:
Dim pType As Type = Utilities.GetPropertyType(propertyInfo.PropertyType)
up above this check.
Copyright (c) Marimer LLC