2013-06-28 541 views
0

我使用VS2010,NHibernate 3.1.0.4000fluent 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 
{ 
} 

我mappping倍率如下:

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鑑別填充在映射覆蓋的正確和醫生和patientstops可以堅持。

但後來我得到的錯誤: System.Data.SqlClient.SqlException : Invalid object name 'HUBSTOP'

所以我再次使用的表名,但現在我得到以下錯誤: Cannot insert the value NULL into column 'StopType'

爲什麼沒有在第一表鑑別工作地方,在停止映射覆蓋?

回答

0

嘗試重寫

public class AutomappingConfiguration : DefaultAutomappingConfiguration 
{ 
    public override bool IsDiscriminated(System.Type type) 
    { 
     var types = new System.Type[] { typeof(Stop), typeof(WorkStop) }; 
     return base.IsDiscriminated(type) || types.Contains(type); 
    }