【发布时间】:2011-12-01 13:38:48
【问题描述】:
我使用 NHibernate 和 NullObject 模式来简化我的视图。 我使用 James Gregory 找到的解决方案 here
public Address GetAddressOrDefault()
{
return Address ?? new NullAddress();
}
而且 Person 有一个 Address 属性等等......
在我尝试为没有地址的人保存我的 Person 对象之前,这非常有效。由于我创建了 NullPerson 对象的新实例,NHibernate 将尝试保存它。并给我这个:
ids for this class must be manually assigned before calling save():
有什么方法可以让 NHibernate 不尝试保存我的 NullObjects?或者我还有什么其他方法可以攻击这个吗?
【问题讨论】:
标签: c# nhibernate fluent-nhibernate null-object-pattern