NHibernate mapping with a class hierarchy whose base class is abstract and the discriminator is not a string

后端 未结 1 1566
心在旅途
心在旅途 2021-02-08 17:21

Here are the domain model classes:

public abstract class BaseClass
{
...
}

public class ChildClass : BaseClass
{
...
}

Note that the parent cl

1条回答
  •  梦毁少年i
    2021-02-08 18:05

    I have found a workaround but this seems so like a patch... I added the following to the mapping file:

    SetAttribute("discriminator-value", "-1");
    

    It seems to instruct FNH not to use a string (I think it uses the class name) for the abstract base class. To make it work with the -1 value, I also changed my discriminator type from byte to sbyte.

    Edit: I missed that: this is the second parameter to DiscriminateSubClassesOnColumn that takes the default value. So the correct answer to my question is:

    DiscriminateSubClassesOnColumn("Type", (sbyte)-1)
    

    0 讨论(0)
提交回复
热议问题