Problem with nullable properties

Posts   
 
    
Posts: 44
Joined: 02-May-2014
# Posted on: 28-May-2014 10:33:08   

Hello,

I create a model map on tables with nullable columns. It generate a class with properties like this :

[Browsable(true)]
public virtual Nullable<System.Decimal> VatRate
{
    get { return (Nullable<System.Decimal>)GetValue((int)UnbundlingPotFieldIndex.VatRate, false); }
    set { SetValue((int)UnbundlingPotFieldIndex.VatRate, value); }
}

And when I try to set the value to null

this._unbundlingPotEntity.VatRate = null;

it throw the following exception : Object of type 'System.DBNull' cannot be converted to type 'System.Nullable`1[System.Decimal]'.

How can I do this ?

Thanks,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39873
Joined: 17-Aug-2003
# Posted on: 28-May-2014 15:14:27   

stack trace? Is this in a query?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 44
Joined: 02-May-2014
# Posted on: 28-May-2014 15:25:10   

Hi Otis,

Here is the stacktrace. It's not in a query. I also have bound this property on a spinEdit control (which accept null value), maybe it's linked.

   at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
   at System.Windows.Forms.BindToObject.SetValue(Object value)
   at System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)
   at System.Windows.Forms.Binding.Target_PropertyChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChangedCore(EventArgs e)
   at DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit.RaiseEditValueChangedCore(EventArgs e)
   at DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChanged(EventArgs e)
   at DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit.RaiseEditValueChanged(EventArgs e)
   at DevExpress.XtraEditors.BaseEdit.RaiseEditValueChanged()
   at DevExpress.XtraEditors.BaseEdit.OnEditValueChanged()
   at DevExpress.XtraEditors.TextEdit.OnEditValueChanged()
   at DevExpress.XtraEditors.BaseEdit.OnEditValueChanging(ChangingEventArgs e)
   at DevExpress.XtraEditors.BaseEdit.set_EditValue(Object value)
   at DevExpress.XtraEditors.SpinEdit.set_EditValue(Object value)
   at AtlasModuleUnbundling.XtraFormPotEdit.ChangeVatUse(Boolean activate) in c:\_Dev\Projects\Atlas\trunk\Modules\AtlasModuleUnbundling\Form\XtraFormPotEdit.cs:line 277
   at AtlasModuleUnbundling.XtraFormPotEdit.chkEditVatUse_CheckedChanged(Object sender, EventArgs e) in c:\_Dev\Projects\Atlas\trunk\Modules\AtlasModuleUnbundling\Form\XtraFormPotEdit.cs:line 338
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit.RaiseCheckedChanged(EventArgs e)
   at DevExpress.XtraEditors.CheckEdit.set_EditValue(Object value)
   at DevExpress.XtraEditors.CheckEdit.set_CheckState(CheckState value)
   at DevExpress.XtraEditors.CheckEdit.Toggle()
   at DevExpress.XtraEditors.BaseCheckEdit.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
   at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
   at DevExpress.XtraEditors.BaseEdit.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at AtlasModuleUnbundling.XtraUcUnbundlingPotView.EditPot(UnbundlingPotEntity unbundlingPotEntity) in c:\_Dev\Projects\Atlas\trunk\Modules\AtlasModuleUnbundling\Form\XtraUcUnbundlingPotView.cs:line 142
   at AtlasModuleUnbundling.XtraUcUnbundlingPotView.bBtnEditPot_ItemClick(Object sender, ItemClickEventArgs e) in c:\_Dev\Projects\Atlas\trunk\Modules\AtlasModuleUnbundling\Form\XtraUcUnbundlingPotView.cs:line 290
   at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
   at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPressItem(DXMouseEventArgs e, RibbonHitInfo hitInfo)
   at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPress(DXMouseEventArgs e, RibbonHitInfo hitInfo)
   at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnMouseUp(DXMouseEventArgs e)
   at DevExpress.XtraBars.Ribbon.Handler.RibbonHandler.OnMouseUp(DXMouseEventArgs e)
   at DevExpress.XtraBars.Ribbon.RibbonControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
   at DevExpress.XtraBars.Ribbon.RibbonControl.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at DevExpress.Utils.Win.Hook.ControlWndHook.CallWindowProc(IntPtr pPrevProc, IntPtr hWnd, Int32 message, IntPtr wParam, IntPtr lParam)
   at DevExpress.Utils.Win.Hook.ControlWndHook.WindowProc(IntPtr hWnd, Int32 message, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Atlas.Program.Main() in c:\_Dev\Projects\Atlas\trunk\General\Atlas\Program.cs:line 27
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39873
Joined: 17-Aug-2003
# Posted on: 28-May-2014 16:35:02   

Check what the default value is for 'null' in the controls. It seems it is set to DBNull.Value, which is of course not a valid value.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 44
Joined: 02-May-2014
# Posted on: 28-May-2014 16:41:33   

Thanks Otis simple_smile