当布尔参数的值为 false 时,方法不执行
Method does not execute when boolean parameter has a value of false
我已将问题隔离到调用存储过程的 BOM 方法中的以下代码行:
if ((includeAgeSeventeenAndUnder == CodeFluentPersistence.DefaultBooleanValue))
{
return null;
}
if ((includeAgeEighteenAndOver == CodeFluentPersistence.DefaultBooleanValue))
{
return null;
}
因为 CodeFluentPersistence.DefaultBooleanValue 等于 False。任何时候将 false 参数传递给该方法,该方法都会退出并且 returns null。我该如何防止这种情况?
我通过将 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>
我已将问题隔离到调用存储过程的 BOM 方法中的以下代码行:
if ((includeAgeSeventeenAndUnder == CodeFluentPersistence.DefaultBooleanValue))
{
return null;
}
if ((includeAgeEighteenAndOver == CodeFluentPersistence.DefaultBooleanValue))
{
return null;
}
因为 CodeFluentPersistence.DefaultBooleanValue 等于 False。任何时候将 false 参数传递给该方法,该方法都会退出并且 returns null。我该如何防止这种情况?
我通过将 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>