Splitting NHibernate entity row storage across multiple tables

社会主义新天地 提交于 2020-01-07 05:40:13

问题


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

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

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


回答1:


You can try NHibernate Shards (sources at http://sourceforge.net/projects/nhcontrib/)




回答2:


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.



来源:https://stackoverflow.com/questions/4251687/splitting-nhibernate-entity-row-storage-across-multiple-tables

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