Fluent NHibernate- ClassMap inheritance?

2019-05-29 04:06发布

In an earlier question (unrelated to Fluent NHibernate- I've switched as a result of my problem) I outlined a table layout issue I'm having where I need to split my Listing entities across a number of tables depending on what country they're from. It's for performance reasons- effectively, I want tables for Listing_UK, Listing_FR, etc.

Now, I thought I'd hit the jackpot with Fluent, and I'm 90% there- but I've got stuck. I have a Listing class, and a Listing_UK class that inherits from it. As such, something like:

Listing testListing = new Listing_UK() as Listing

works fine. However, I've tripped up on the ClassMaps. I had intended to make a static void that'll do my mapping for all the tables like so:

public static void DoMap(ClassMap<Listing> map) {
        map.Id(x => x.ListingCode)
            .GeneratedBy.HiLo("10000");
    }

but I need to convert the ClassMap<Listing_UK> to a ClassMap<Listing> in order to pass it in- and I can't. Something like this (though it doesn't make sense, as such) doesn't work:

ClassMap<Listing> test = new ClassMap<Listing_UK> as ClassMap<Listing>

Any ideas how I can gracefully handle this?

1条回答
再贱就再见
2楼-- · 2019-05-29 04:38

OK, I found a solution after some intensive Googling. Hopefully this will help someone who ends up in the same situation I did:

http://geekswithblogs.net/nharrison/archive/2010/07/09/inheriting-a-class-map-in-fluent-nhibernate.aspx

查看更多
登录 后发表回答