代码之家  ›  专栏  ›  技术社区  ›  SharePoint Newbie

如何告诉nhibernate加载一个组件不为空,即使它的所有属性都为空?

  •  4
  • SharePoint Newbie  · 技术社区  · 15 年前

    我有一个包含日期时间的日期类?类(帮助模拟日期时间。现在,我们的域等)。

    日期类类类只有一个受保护的属性:datetime?日期

    public class Date
    {
        protected DateTime? date;
    }
    
    // mapping in hbm
    <component name="CompletedOn">
      <property column="StartedOn" name="date" access="field" not-null="false" />
    </component>
    

    从NHibernate文件:

    Like all value types, components do not support shared references. The null value semantics of a component are ad hoc. When reloading the containing object, NHibernate will assume that if all component columns are null, then the entire component is null. This should be okay for most purposes.

    我能改变这种行为吗?我希望我的日期类被实例化,即使日期为空。

    谢谢,

    2 回复  |  直到 15 年前
        1
  •  4
  •   Diego Mijelshon    15 年前

    我认为你不能无视这种行为。

    但是,让NH像往常一样工作(检索空值)并将其包装在域模型中通常比较容易。

    但从我所看到的来看,您这样做可能是为了演示(数据绑定?)关心。只是暴露一个 DateTime? ?

        2
  •  5
  •   Jamie Ide    15 年前

    我认为您可以通过使用实现IPostLoadEventListener的侦听器来实现这种行为。加载实体后,可以检查组件是否为空,如果为空,则可以新建。