locked
How do I set the default value to 0 in a property with "money" as the type? RRS feed

  • Question

  • I have an entity with several properties with the "Money" data type.  I also have a Money property with a "computed" value that shows the sum of the other money type properties. However, a total will not display if any of the other fields are left with a null value. Is there way to make the default value set to "0"?  I am using c#.  Thank you.
    Sunday, January 11, 2015 2:26 PM

Answers

  • Mark, there's a very basic .NET method on every nullable object: GetValueOrDefault

    EDIT: Now I see...please avoid duplicating questions...

    To be clear:

    • Put GetValueOrDefault on every nullable field used inside your 'TotalDue_Compute' sub
    • You don't need to define 'TotalDue' as Nullable anymore
    • Edited by technetcolmar Tuesday, January 13, 2015 8:26 AM
    • Marked as answer by Angie Xu Monday, January 19, 2015 1:34 AM
    Tuesday, January 13, 2015 8:01 AM

All replies

  • Hi Mark,

    Welcome to Lightswitch forum.

    From your description above, here is a simple way to do that, you can set the Money type to "NOT NULL" when you design the screen, in this way, user must enter money value, it will be helpful for you to calculate.

    Hope it helps.

    Best regards,

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 12, 2015 7:27 AM
  • Mark, there's a very basic .NET method on every nullable object: GetValueOrDefault

    EDIT: Now I see...please avoid duplicating questions...

    To be clear:

    • Put GetValueOrDefault on every nullable field used inside your 'TotalDue_Compute' sub
    • You don't need to define 'TotalDue' as Nullable anymore
    • Edited by technetcolmar Tuesday, January 13, 2015 8:26 AM
    • Marked as answer by Angie Xu Monday, January 19, 2015 1:34 AM
    Tuesday, January 13, 2015 8:01 AM