nhibernate many to many with multiple table

柔情痞子 提交于 2019-12-11 20:25:54

问题


Good morning,

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.

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?

Best regards,

Veasna


回答1:


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

Chapter 24. Best Practices

Don't use exotic association mappings.

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.

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

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

Please, check these:

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

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..



来源:https://stackoverflow.com/questions/29158253/nhibernate-many-to-many-with-multiple-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!