NHibernate中的逆属性 [英] Inverse Attribute in NHibernate

查看:58
本文介绍了NHibernate中的逆属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用逆属性?如果我没记错的话,对于一对多的关系,必须将inverse属性设置为true.对于多对多关系,必须将实体类逆属性之一设置为true,将另一个属性设置为false.

How do I use the Inverse Attribute? If I am not mistaken, for one to many relationships the inverse attribute must be set to true. For many-to-many relationships, one of the entity class inverse attributes must be set to true and another set to false.

任何人都可以对此有所了解吗?

Anyone can shed some lights on this?

推荐答案

inverse属性不得设置为true ...

The inverse attribute must not be set to true ...

您可以使用inverse属性指定关联的所有者". (一个关联只能有一个所有者,因此一端必须设置为反向,而另一端必须设置为非反向"). (所有者:inverse=false;非所有者:inverse=true)

You use the inverse attribute to specify the 'owner' of the association. (An association can have only one owner, so one end has to be set to inverse, the other has to be set to 'non inverse'). (Owner: inverse=false; Non-owner: inverse=true)

在一对多关联中,如果不将集合标记为反向,则NHibernate将执行附加的UPDATE. 实际上,在这种情况下,NHibernate首先会插入集合中包含的实体,必要时插入拥有集合的实体,然后更新集合实体",以便设置外键和关联被制造. (请注意,这也意味着数据库中的外键应该可以为空).

In a one-to-many association, if you do not mark the collection as the inverse end, then NHibernate will perform an additional UPDATE. In fact, in this case, NHibernate will first insert the entity that is contained in the collection, if necessary insert the entity that owns the collection, and afterwards, updates the 'collection entity', so that the foreign key is set and the association is made. (Note that this also means that the foreign key in your DB should be nullable).

当您将集合结束标记为反向"时,NHibernate将首先保留拥有"该集合的实体,然后将保留该集合中的实体,从而避免了其他UPDATE语句.

When you mark the collection end as 'inverse', then NHibernate will first persist the entity that 'owns' the collection, and will persist the entities that are in the collection afterwards, avoiding an additional UPDATE statement.

因此,在双向关联中,您总是有一个反向端.

So, in an bi-directional association, you always have one inverse end.

这篇关于NHibernate中的逆属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆