流畅的nhibernate自动化配置不起作用

时间:2014-09-09 06:53:28

标签: c# nhibernate fluent-nhibernate

流利配置

FluentConfiguration fc = Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString)               
            );

映射配置

fc.ExposeConfiguration(cfg => 
         cfg.SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, currentSessionContextClass))
  .ExposeConfiguration(cfg => 
         cfg.SetProperty(NHibernate.Cfg.Environment.CommandTimeout, "120")
   );                

fc.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<BasicEntity>(autoMappingConf)          
               .UseOverridesFromAssemblyOf<AccountMappingOverride>()
               .Conventions.Add(
                    DefaultCascade.SaveUpdate(),
                    new DefaultStringLengthConvention(),
                    new DefaultDecimalConvention()))           
                );
        return fc;

内部异常是未使用数据库方法配置的数据库。 也是不完整的映射。

1 个答案:

答案 0 :(得分:-1)

我只是改变位置

fc.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<BasicEntity>

(autoMappingConf)          

               .UseOverridesFromAssemblyOf<AccountMappingOverride>()
               .Conventions.Add(
                    DefaultCascade.SaveUpdate(),
                    new DefaultStringLengthConvention(),
                    new DefaultDecimalConvention()))           
                );


fc.ExposeConfiguration(cfg => 

         cfg.SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, 

currentSessionContextClass))

  .ExposeConfiguration(cfg => 

         cfg.SetProperty(NHibernate.Cfg.Environment.CommandTimeout, "120")

   );             

return fc;