Search code examples
codefluent

Method does not execute when boolean parameter has a value of false


I have isolated the problem to the following lines of code in the BOM method that calls the stored procedure:

        if ((includeAgeSeventeenAndUnder == CodeFluentPersistence.DefaultBooleanValue))
        {
            return null;
        }
        if ((includeAgeEighteenAndOver == CodeFluentPersistence.DefaultBooleanValue))
        {
            return null;
        }

Because CodeFluentPersistence.DefaultBooleanValue equals False. Anytime a parameter of false is passed to the method, the method exits and returns null. How can I prevent this?


Solution

  • I got it working by setting the modeNullable to true.

    <cf:method name="Load">
      <cf:body text="LOADONE(date  startDate, date endDate, bool includeAgeSeventeenAndUnder, bool includeAgeEighteenAndOver,int sisProgramId) RAW  " rawText="This has been deleted because it is not relevent to question" language="tsql" />
      <cf:parameter typeName="bool" name="includeAgeSeventeenAndUnder" modelNullable="True" />
      <cf:parameter typeName="bool" name="includeAgeEighteenAndOver" modelNullable="True" />
    </cf:method>
    

    Meziantou suggestion is actually preferable since I really don't want the parameters to be nullable. The below snippet demonstrates the correct way to disable the default value check.

    <cf:method name="Load">
      <cf:body text="LOADONE(date  startDate, date endDate, bool includeAgeSeventeenAndUnder, bool includeAgeEighteenAndOver,int sisProgramId) RAW  " rawText="This has been deleted because it is not relevent to question" language="tsql" />
      <cf:parameter typeName="bool" cfom:checkDefaultValue="false" name="includeAgeSeventeenAndUnder" modelNullable="False" />
      <cf:parameter typeName="bool" cfom:checkDefaultValue="false" name="includeAgeEighteenAndOver" modelNullable="False" />
    </cf:method>