Fluent NHibernate, working with interfaces

前端 未结 3 644
自闭症患者
自闭症患者 2020-12-01 05:23

I just switched to Fluent NHibernate and I\'ve encountered an issue and did not find any information about it.

Here\'s the case :

public class Field          


        
3条回答
  •  半阙折子戏
    2020-12-01 05:54

    On your Field object, you have an object of type IAddress. This could be implemented by any number of different implementations. With what you are asking, each implementation would have its own mapping, which would introduce any number of difficulties (impossibilities?) for NHibernate to handle.

    A simple example would help to demonstrate. Say you have two IAddress implementations Address1, and Address2. They each are saved in their own table, tblAddress1, and tblAddress2. When you try to load your Field object, all NHibernate knows is that you have something that implements IAddress, it does not know which implementation was persisted. How would it know which mapping to use to retrieve the child object for any given field?

    I'm sure there are more complications, but this example shows why you have to have a mapping for the exact type of object that you have declared.

提交回复
热议问题