【问题标题】:How to set discriminate column type for subclass with FNH?如何使用 FNH 为子类设置区分列类型?
【发布时间】:2010-09-01 14:33:22
【问题描述】:

FNH 映射中的新SetAttribute() 是什么?我需要在子类上设置我的鉴别器值,因为 String 不是首选 - old post

NH 2.1.2.4000,FNH 1.1.0.689

public class BaseBuildingMap : ClassMap<BaseBuilding>
{
    public BaseBuildingMap()
    {
        Id(x => x.Id);
        DiscriminateSubClassesOnColumn<int>("BuildingType", -1);
    }
}

public class PowerStationMap : SubclassMap<PowerStation>
{
    public PowerStationMap()
    {
        Map(x => x.ElectricityProduction);
    }
}

NHibernate.MappingException:无法将鉴别器值格式化为实体 Model.Test.PowerStation 的 SQL 字符串 ---> System.FormatException:输入字符串的格式不正确。

我需要设置SetAttribute("discriminator-value", "-1");,但是没有这个方法。

编辑 1

问题:如何使用 FNH 为子类设置区分列类型?

【问题讨论】:

    标签: c# nhibernate fluent-nhibernate nhibernate-mapping


    【解决方案1】:
    public class PowerStationMap : SubclassMap<PowerStation>
    {
        public PowerStationMap()
        {
            DiscriminatorValue((int)1);
            Map(x => x.ElectricityProduction);
        }
    }
    

    我终于找到了我的答案,它是

    SubclassMap<T>::DiscriminatorValue(object discriminatorValue);
    

    【讨论】:

      【解决方案2】:

      来自Fluent NHibernate 1.0 Release Notes

      移除 SetAttribute - SetAttribute 是一种权宜之计,允许人们在我们不支持他们需要的属性时使用 Fluent NHibernate。我们现在已经竭尽全力支持流畅界面中的所有主要属性,因此您不再需要它了。如果我们遗漏了您需要的任何属性,请告诉我们(或者更好的是,向我们发送拉取请求/补丁)

      【讨论】:

        猜你喜欢
        • 2016-02-19
        • 2011-01-31
        • 1970-01-01
        • 2012-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-20
        • 1970-01-01
        相关资源
        最近更新 更多