我有加載實體的通用方法。我需要檢查空值的結果值。如何檢查代理的空值
public TEntity LoadById(long id)
{
TEntity result = SessionInstance.Load<TEntity>(id);
if (result != null) //This condition is always true
if (result.Id == 0) //Throws ObjectNotFoundException
throw new Exception("Ex Text");
return result;
}
但我的條件(if (result != null)
)永遠是真實的下一行result.Propagate()
是這個消息拋出ObjectNotFoundException
異常:No row with the given identifier exists[RCISP.Domain.Entities.Person#1000]
因爲結果實體是一個代理。 如何在代理中檢查空值的條件?
我很熟悉NHibernate中的Get。我的項目基於'懶惰加載'。我需要在NHibernate中加載。我該怎麼辦? – Ehsan
@Ehsan:這個Propagate方法在做什麼? –
此方法是加載實體後的強制方法。假設它對於非空的檢查是必需的。 – Ehsan