Nhibernate / 建议映射属性和 id
出于过滤目的,我想在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在保存/更新实体时可能会遇到问题。在这种情况下,只需将
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.