gpt4 book ai didi

nhibernate - 即使组件的所有属性都为空,我如何告诉 NHibernate 将组件加载为非空?

转载 作者:行者123 更新时间:2023-12-03 12:05:11 24 4
gpt4 key购买 nike

我有一个包含 DateTime 的 Date 类?类(有助于模拟 DateTime.Now、我们的域等)。

Date 类只有一个 protected 属性: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.

我可以覆盖这种行为吗?即使日期为空,我也希望实例化我的 Date 类。

谢谢,

最佳答案

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

关于nhibernate - 即使组件的所有属性都为空,我如何告诉 NHibernate 将组件加载为非空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2880008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com