在多个表之间拆分NHibernate实体行存储 [英] Splitting NHibernate entity row storage across multiple tables

查看:78
本文介绍了在多个表之间拆分NHibernate实体行存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的NHibernate设置中,我们有一个Listing实体.出于数据库性能的考虑,我们希望按国家/地区将其存储分为多个表(网站的设置方式,没有人一次可以在一个以上的国家/地区进行搜索).因此,Listing_US,Listing_FR等.

In our NHibernate setup, we have a Listing entity. For DB performance reasons, we want to split the storage of it into multiple tables, by country (the way the site is set up, no-one can ever search in more than one country at a time). So, Listing_US, Listing_FR, etc.

两个问题,第一个比第二个重要得多:

Two questions, the first far more important than the second:

  1. NHibernate有什么办法可以帮我完成此映射吗?大概它将基于一个内部字段,该内部字段在Get()生成(我要在其中传递国家代码,或者将其集成到主键中?),然后在Save()上读取.

  1. Is there any way NHibernate can do this mapping for me? Presumably it would be based around an internal field that gets generated on the Get() (where I'd pass in the country code, or perhaps integrate it into the primary key?) and then read on the Save().

是否也将其包含在架构中,并且当从头开始创建整个数据库架构时可以导出吗?

Would it also be included in the schema, and as such be exportable when creating an entire DB schema from scratch?

我刚刚意识到,这将对尝试进行选择造成严重破坏.显然,由于我不想每次都查询每个表(这会破坏性能优势),所以我将不得不具有某种Listing_XX实体,但也许它可以从通用Listing继承吗?不过,我不确定如何将其输入到XML映射中.

I've just realised that this would play havoc with trying to do selects. Obviously, since I don't want to query every table each time (would ruin that performance benefit) I'm going to have to have some kind of Listing_XX entity, but perhaps it could inherit from a generic Listing? I'm not sure how that would feed into the XML mapping, though.

推荐答案

如果您的数据库支持分区表,则最好使用分区表(您没有说要使用哪个数据库).只要您始终查询分区列值集,就可以轻松获得多个表的所有性能优势.

It might be better to use a partitioned table if your DB supports them (you didn't say which DB you're using). As long as you always query with the partitioned column value set, you'll get all the performance advantages of multiple tables without the hassle.

这篇关于在多个表之间拆分NHibernate实体行存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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