流畅的 nhibernate 的多对多性能问题

发布于 2024-10-25 06:53:56 字数 1201 浏览 2 评论 0原文

我遇到的情况是,我有多个多对多关联。在 12 到 15 以上。通过阅读,我发现人们普遍认为多对多关联不是“典型”的,但它们是我能够创建适合我的情况的关联的唯一方法,所以我不确定如何进一步优化。

这是我的基本场景。

class Page {
  IList<Tag> Tags { get; set; }
  IList<Modification> Modifications { get; set; }
  IList<Aspect> Aspects { get; set; }
}

这是我的“核心”课程之一,巧合的是我的核心表之一。我的代码中几乎一半的对象可以具有 IList,其中一些具有 IList,其中 T 具有其自己的IList

正如您所看到的,从面向对象的角度来看,这并不是一个真正的问题。但从数据库的角度来看,这开始引入大量的连接表。

到目前为止,它对我来说效果很好,但我想知道是否有人对我如何改进这个结构有任何想法。我花了很长时间思考,为了达到所需的适当关联水平,我想不出有什么方法可以改进它。我唯一想到的就是为每个具有 IList 的对象创建中间类,但这并没有真正执行 HasManyToMany 所做的任何事情除了引入另一个类之外还没有做。它不会扩展功能,而且据我所知,它不会提高性能。

有什么想法吗?我还担心这种情况下的主键限制。大多数东西都需要能够具有这些属性,但页面对于每个对象来说不能是唯一的,因为它们将在多个对象之间频繁共享和连接。

所有的关系都是单方面的。 (也就是说,Page 不知道它的所有者是什么)。因此,我没有 Inverse() 映射的 HasManyToMany 集合。

另外,我读过类似的问题: 当有很多关联时使用像NHibernate这样的ORM——性能问题

但这确实没有回答我的问题。

I have a situation where I have several many-to-many associations. In the upwards of 12 to 15. Reading around I've seen that it's generally believed that many-to-many associations are not 'typical', yet they are the only way I have been able to create the associations appropriate for my case, so I'm not sure how to optimize any further.

Here is my basic scenario.

class Page {
  IList<Tag> Tags { get; set; }
  IList<Modification> Modifications { get; set; }
  IList<Aspect> Aspects { get; set; }
}

This is one of my 'core' classes, and coincidentally one of my core tables. Virtually half of the objects in my code can have an IList<Page>, and some of them have IList<T> where T has its own IList<Page>.

As you can see, from an object oriented standpoint, this is not really a problem. But from a database standpoint this begins to introduce a lot of junction tables.

So far it has worked fine for me, but I am wondering if anyone has any ideas on how I could improve on this structure. I've spent a long time thinking and in order to achieve the appropriate level of association required, I cannot think of any way to improve it. The only thing I have come up with is to make intermediate classes for each object that has an IList<Page>, but that doesn't really do anything that the HasManyToMany does not already do except introduce another class. It does not extend the functionality and, from what I can tell, it does not improve performance.

Any thoughts? I am also concerned about Primary Key limits in this scenario. Most everything needs to be able to have these properties, but the Pages cannot be unique to each object, because they are going to be frequently shared and joined between multiple objects.

All relationships are one-sided. (That is, a Page has no knowledge of what owns it). Because of this, I also have no Inverse() mapped HasManyToMany collections.

Also, I have read the similar question : Usage of ORMs like NHibernate when there are many associations - performance concerns

But it really did not answer my concerns.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日落 2024-11-01 06:53:56

问题比较模糊。

为什么您认为多对多关系会导致性能问题?您对您的应用程序进行了概要分析吗?

乍一看,如果 Modification 代表一个版本或对一个 Page 的更改,那么它应该是一对多,而不是多对多。也许你还有更多这样的东西。

The question is rather vague.

Why do you assume many-to-many relationships are causing you performance problems? Have you profiled your application?

At a glance, if Modification represents a version or change to a Page, it should be one-to-many, not many-to-many. Maybe you have more of those.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文