用多个表休眠多对多 [英] nhibernate many to many with multiple table

查看:97
本文介绍了用多个表休眠多对多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好

我牢记以下模式,如下图所示登录.

I have the following schemas in mind which the login as describe below image.

通常,关联表将包含表位置",部门"和资格"的关键字.

Normally, the association table would contain the Key of table Position, Division, and Qualification.

我不确定这个模式是否格式正确.如果可以,请指导我如何在Nhibernate XML模式和PoCo类中表示它?

I am not sure whether this schema is well form or not.If it does could you please guide me how to represent it in Nhibernate XML schemas and PoCo class?

最诚挚的问候,

Veasna

推荐答案

您的模式(您的想法)是概念证明:不要使用many-to-many映射.

Your schema, your ideas, are prove of concept: do not use many-to-many mapping.

请勿使用外来关联映射.

真正的多对多关联的好用例很少.大多数时候,您需要存储在链接表"中的其他信息.在这种情况下,对中间链接类使用两个一对多关联会更好.实际上,我们认为大多数关联是一对多和多对一的,使用任何其他关联样式时都应小心,并问自己是否真的必要.

Good usecases for a real many-to-many associations are rare. Most of the time you need additional information stored in the "link table". In this case, it is much better to use two one-to-many associations to an intermediate link class. In fact, we think that most associations are one-to-many and many-to-one, you should be careful when using any other association style and ask yourself if it is really neccessary.

我的建议是:使配对对象为first level citizen的标准实体,并带有所有标准的东西.

My suggestion would be: Make your pairing object the first level citizen, standard entity, with all standard stuff.

它自己拥有,因此请首先替换 ID .

Its own, surrogate ID at first place.

一旦您尝试按部门查询排名,反之亦然,这将为您带来很多利润

That will bring you lot of profit later, once you will try to query Position by Division and vice versa

请检查以下内容:

  • many-to-many with extra columns nhibernate
  • Nhibernate: How to represent Many-To-Many relationships with One-to-Many relationships?

摘要:我将介绍(位置和部门并排)具有其一个ID-Qualification的全新对象.上面提到的都多对一,并且被称为IList<Qualification> 一对多.您将能够提供以后需要的任何过滤条件.

Summary: I would introduce (side by side of Position and Division) brand new object with its one ID - Qualification. That would have many-to-one reference to both above and will be reference as IList<Qualification> one-to-many. You'll be able to provide any filtering you'd be asked for later..

这篇关于用多个表休眠多对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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