当布尔参数的值为false

时间:2015-12-03 19:59:36

标签: codefluent

我已将问题隔离到调用存储过程的BOM方法中的以下代码行:

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

因为CodeFluentPersistence.DefaultBooleanValue等于False。只要将false参数传递给方法,该方法就会退出并返回null。我该如何防止这种情况?

1 个答案:

答案 0 :(得分:2)

我通过将modeNullable设置为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建议实际上是可取的,因为我真的不希望参数可以为空。下面的代码段演示了禁用默认值检查的正确方法。

<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>