NHibernate映射/设计建议 - 连接表

时间:2022-10-10 18:53:03

I have a design issue that I would appreciate some input on.

我有一个设计问题,我会很感激一些输入。

I would like to make an calendar event system based on the following 4 tables:

我想基于以下4个表创建一个日历事件系统:

tb_events

id, date, summary,

id,日期,摘要,


tb_group

id, name, parent, lineage,

id,name,parent,lineage,


tb_course

id, name,


tb_staff

id, name, email,

id,姓名,电子邮件,


The event class is currently set up as

事件类当前设置为

id
summary
date
calDetails IList<CalDetails>

class CalDetail

id
name

My dilemma is whether to use one join table - linking the eventID to the ID of a group,course or staff or whether to add group, course staff collections to the event class.

我的困境是是否使用一个连接表 - 将eventID链接到组,课程或人员的ID,或者是否将组,课程人员集合添加到事件类。

Having a collection for each would be easier to map in hibernate but I'm wondering what kind of performance hit I will get using 3 joins. (The event table may have up to 10-20000 records). Also, as I only need the name property when viewing the event, using the one collection would make it easier to add another kind of 'event detail' to the mix.

拥有一个集合可以更容易在hibernate中进行映射,但我想知道使用3个连接可以获得什么样的性能。 (事件表最多可包含10-20000条记录)。此外,由于我在查看事件时只需要name属性,因此使用一个集合可以更轻松地向混合中添加另一种“事件详细信息”。

If I were to go with the one collection, is it possible to map it in NHibernate. I've looked around for examples but can't find any. Which kind of got me thinking that perhaps this wasn't a good way to go about it.

如果我要使用一个集合,是否可以在NHibernate中映射它。我环顾四周寻找例子,却找不到任何例子。哪种让我觉得这可能不是一个好方法。

Anyway, I'd be grateful of any thoughts.

无论如何,我会感激任何想法。

2 个解决方案

#1


1  

If you do the naive approach of using 3 joins, you may get a huge performance hit. Ayende has some examples of using MultiCriteria to bring performance back in line.

如果你使用3个连接的天真方法,你可能会受到巨大的性能影响。 Ayende有一些使用MultiCriteria来恢复性能的例子。

You can also go the subclasses route, if it makes sense.

如果有意义的话,你也可以去子类路线。

#2


2  

Be careful not to optimize for performance prematurely. It's fairly unlikely you'll have performance problems, and in the event that they surface they are fairly easy to circumvent. I would start out by going the most frictionless route. You'll be happier that way.

注意不要过早优化性能。你不太可能遇到性能问题,如果它们浮出水面,它们很容易被规避。我会从最无摩擦的路线开始。你会这样开心的。

#1


1  

If you do the naive approach of using 3 joins, you may get a huge performance hit. Ayende has some examples of using MultiCriteria to bring performance back in line.

如果你使用3个连接的天真方法,你可能会受到巨大的性能影响。 Ayende有一些使用MultiCriteria来恢复性能的例子。

You can also go the subclasses route, if it makes sense.

如果有意义的话,你也可以去子类路线。

#2


2  

Be careful not to optimize for performance prematurely. It's fairly unlikely you'll have performance problems, and in the event that they surface they are fairly easy to circumvent. I would start out by going the most frictionless route. You'll be happier that way.

注意不要过早优化性能。你不太可能遇到性能问题,如果它们浮出水面,它们很容易被规避。我会从最无摩擦的路线开始。你会这样开心的。