在NHibernate中将子ID设置为Parent ID

时间:2012-08-24 14:45:54

标签: c# nhibernate relationship

在我的应用程序中,我有一个User类,其中只有一个Settings类。一对一的关系 我为用户提供了一个简单的NHibernate映射:

/// NHibernate declarations etc
<id name="squid" type="guid">
  <generator class="assigned" />
</id>
/// Properties
<one-to-one class="Settings" name="Settings" outer-join="true" cascade="save-update" />
/// Close tags & end file

我的设置类是

/// NHibernate declarations
<id name="squid" type="guid">
  <generator class="assigned" />
</id>
/// Properties, close tags & end of file

因此,您可以看到我的用户被分配了一个基于其Active Directory帐户的guid(或在我的单元测试中,由Guid.NewGuid()生成的新Guid)

NHibernate是否可以将设置GUID神奇地指定为用户GUID?

1 个答案:

答案 0 :(得分:1)

据我所知,您的示例最好将Settings定义为Value对象,因为没有User它就没有意义。这是Nhibernate用法的常见做法。您可以阅读有关此here的更多信息。

相关问题