我正在使用VS2010,NHibernate 3.1.0.4000
并且fluent Nhibernate 1.2.0.712.
我的程序包含以下类层次结构:
public abstract class Stop
{
}
public abstract class WorkStop : Stop
{
}
public class PatientStop : WorkStop
{
}
public class DoctorStop : WorkStop
{
}
public class HubStop : Stop
{
}
我的映射覆盖如下:
public class StopMappingOverride : IAutoMappingOverride<Stop>
{
public void Override(AutoMapping<Stop> mapping)
{
mapping.DiscriminateSubClassesOnColumn("StopType");
mapping.SubClass<HubStop>("HubStop");
mapping.SubClass<WorkStop>("WorkStop").Abstract();
mapping.References(x => x.Planning).Cascade.None();
}
}
public class WorkStopMappingOverride : IAutoMappingOverride<WorkStop>
{
public void Override(AutoMapping<WorkStop> mapping)
{
//mapping.Table("Stop");
mapping.DiscriminateSubClassesOnColumn("StopType");
mapping.SubClass<DoctorStop>("DoctorStop");
mapping.SubClass<PatientStop>("PatientStop");
mapping.HasMany(d => d.Tasks).KeyColumn("StopId")
.AsSet()
.Access.CamelCaseField(Prefix.Underscore);
mapping.References(x => x.Doctor).Cascade.None();
}
}
public class DoctorStopMappingOverride : IAutoMappingOverride<DoctorStop>
{
public void Override(AutoMapping<DoctorStop> mapping)
{
mapping.References(x => x.Practice).Cascade.None();
mapping.HasMany(d => d.Protocols).KeyColumn("StopId")
.AsSet()
.Access.CamelCaseField(Prefix.Underscore);
mapping.HasMany(d => d.Materials).KeyColumn("StopId")
.AsSet()
.Access.CamelCaseField(Prefix.Underscore);
}
}
public class PatientStopMappingOverride : IAutoMappingOverride<PatientStop>
{
public void Override(AutoMapping<PatientStop> mapping)
{
mapping.References(x => x.Patient).Cascade.None();
}
}
public class HubStopMappingOverride : IAutoMappingOverride<HubStop>
{
public void Override(AutoMapping<HubStop> mapping)
{
}
}
以上用于在以前的项目中工作。除了工作台的额外抽象级别,那是新的。但是然后 hubstop 应该仍然可以工作,我将在下面说明。
何时按原样使用映射覆盖,我收到错误:
System.Data.SqlClient.SqlException : Invalid object name 'WORKSTOP'
所以我想,如果我指定表名怎么办,是的,因为 WorkStop 上的映射覆盖,鉴别器被正确填写,并且医生和病人站可以被持久化。
但后来我得到了错误:
System.Data.SqlClient.SqlException : Invalid object name 'HUBSTOP'
所以我再次使用了表名,但现在我收到以下错误:
Cannot insert the value NULL into column 'StopType'
为什么表鉴别器首先在停止映射覆盖时不起作用?