Programming to interfaces while mapping with Fluent NHibernate

后端 未结 5 1233
闹比i
闹比i 2020-12-01 01:22

I have been whipped into submission and have started learning Fluent NHibernate (no previous NHibernate experience). In my project, I am programming to interfaces to reduce

5条回答
  •  误落风尘
    2020-12-01 01:59

    UPDATE: using union-subclass is not supported via the fluent interface fluent-nhibernate provides. You'll have to use a regular hbm mapping file and add it.

    I too I'm trying do this with fluent NHibernate. I don't think it should be a problem mapping interfaces. You want to use an inheritance strategy, specifically the table-per-concrete-class strategy.

    Essentially, you create a mapping definition for the base class (in this case your interface) and specify how to NHibernate should deal with implementers by using union-subclass.

    So, for example, this should allow you to make polymorphic associations:

    
    
            
                    
            
    
            
                    
            
    
            
                    
            
            ...
     
    

    Note how the Id is the same for all concrete implementers. NHibernate required this. Also, IAccountManager table doesn't actually exist.

    You can also try and leverage NHibernate's Implicit Polymorphism (documented below the table-per-concrete-class strategy) - but it has tons of limitations.

提交回复
热议问题