How to map an interface in nhibernate?

前端 未结 3 367
不知归路
不知归路 2020-12-19 06:17

I\'m using two class NiceCustomer & RoughCustomer which implment the interface ICustomer.

The ICustomer has f

3条回答
  •  清酒与你
    2020-12-19 06:54

    how are you querying? If you're using HQL you need to import the interface's namespace with an HBM file with this line:

    
    

    If you're using Criteria you should just be able to query for ICustomer and it'll return both customer types.

    If you're mapping a class that has a customer on it either through a HasMany, HasManyToMany or References then you need to use the generic form:

    References(f=>f.Customer)
    

    If you want it to cope with either, you'll need to make them subclasses

    Subclassmap
    

    In which case I think you'll need the base class Customer and use that for the generic type parameter in the outer class:

    References(f=>f.Customer)
    

    Regardless, you shouldn't change your domain model to cope with this, it should still have an ICustomer on the outer class.

    I'm not sure if the 1.0RTM has the Generic form working for References but a quick scan of the changes should show the change, which I think is a two line addition.

提交回复
热议问题