Nhibernate / 建议映射属性和 id

发布于 2024-11-14 10:12:49 字数 942 浏览 7 评论 0原文

出于过滤目的,我想在 nhibernate 中建议映射属性和 id。

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="BusinessObjets.ItemShopping,BusinessObjets" table="ADN_Monture" lazy="true">
     <many-to-one name="Manufacturer" column="IDManufacturer" cascade="save-update" not-null="true" />
<property name="IDManufacturer" column="IDManufacturer" type="int" />
  </class>
</hibernate-mapping>

在这种情况下,它将建议Manufacturer Type 的Manufacturer 属性和IDManufacturer (int)。 int 将是只读属性,仅用于过滤数据。 例如:

var result = from item in session.Query<ItemShopping>() select item).ToList<ItemShopping();

然后使用 linq to object with a id 过滤结果。 nhibernate 进程(插入/更新)有什么缺点吗?

问候

编辑

安装nhibernate profiler后,我注意到仅基于外键(item.Manufacturer.IdManufacturer)的过滤器不使用代理。所以不存在性能问题。 有人可以确认吗?

For filtering purpose, I'd like to propose in nhibernate both the mapped property and the id.

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="BusinessObjets.ItemShopping,BusinessObjets" table="ADN_Monture" lazy="true">
     <many-to-one name="Manufacturer" column="IDManufacturer" cascade="save-update" not-null="true" />
<property name="IDManufacturer" column="IDManufacturer" type="int" />
  </class>
</hibernate-mapping>

In this case, it would propose either a Manufacturer property of the Manufacturer Type and a IDManufacturer (int).
The int would be a readonly property and would only be used to filter the data.
For example :

var result = from item in session.Query<ItemShopping>() select item).ToList<ItemShopping();

and then filter the result with linq to objects with an id.
Is there any drawback in the nhibernate process (insert / update) ?

Regards

Edit

Well after installing nhibernate profiler, I notice that a filter based only on the foreign key (item.Manufacturer.IdManufacturer) doesn't use the proxy. So there is no performance problem.
Can someone confirm ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双马尾 2024-11-21 10:12:49

您在保存/更新实体时可能会遇到问题。在这种情况下,只需将 update="false" 放在附加的 Id 属性上,它就会像超级按钮一样工作。如果您只是查询,没问题。顺便说一句,即使您查询多对一,您也不应该遇到性能问题。已知 NH 会根据 Id 发出查询,并且不会仅仅为了发出查询而急切地获取任何内容。

You can experience problems in saving/updating the entity. In this case just put update="false" on the additional Id property, and it should work like a charm. No problem if you are just querying. BTW you should not have performance issues even if you query for the many to one. NH known to issue a query based on the Id and does not eagerly fetch anything just for issuing the query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文