我的模型包含一个具有数字属性的实体:
<cf:entity name="Land">
<cf:property name="Id" key="true" />
<cf:property name="Landcode" typeName="ushort" nullable="false" usePersistenceDefaultValue="false" />
<cf:method name="LoadByLandcode"
body="LOADONE(ushort landCode) WHERE Landcode = @landcode">
</cf:method>
</cf:entity>
LoadByLandcode 方法生成的代码如下所示:
public static Land LoadByLandcode(ushort landCode)
{
if ((landCode == CodeFluentPersistence.DefaultUInt16Value))
{
return null;
}
Land land = new Land();
CodeFluent.Runtime.CodeFluentPersistence persistence = CodeFluentContext.Get(BusinessLayerStoreName).Persistence;
persistence.CreateStoredProcedureCommand(null, "Land", "LoadByLandcode");
persistence.AddParameter("@landCode", landCode);
System.Data.IDataReader reader = null;
try
{
reader = persistence.ExecuteReader();
if ((reader.Read() == true))
{
land.ReadRecord(reader, CodeFluent.Runtime.CodeFluentReloadOptions.Default);
land.EntityState = CodeFluent.Runtime.CodeFluentEntityState.Unchanged;
return land;
}
}
finally
{
if ((reader != null))
{
reader.Dispose();
}
persistence.CompleteCommand();
}
return null;
}
如果提供的 landCode 参数为 0,为什么 CodeFluent 返回 null?我不希望这种情况发生,因为landCode 0 也是数据库中的有效值。我怎样才能改变这种行为?