问题
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:
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?
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