private ISessionFactory getSessionFactory() { if (_sessionFactory == null) { MyAutoMappingConfiguration mappingCfg = new MyAutoMappingConfiguration(); MySQLConfiguration dataConfig = MySQLConfiguration.Standard .ShowSql() .ConnectionString(s => s.FromConnectionStringWithKey("conn")); _sessionFactory = Fluently.Configure() .Database(dataConfig) .Mappings( /*automampping can't work with override * m => m.AutoMappings.Add(AutoMap.AssemblyOf<NModel.Product>(mappingCfg) * .Conventions.Setup(c=>{ * c.Add<DefaultStringLengthConvention>(); * }) * .Override<NModel.Product>(map => * { * map.Map(x => x.NTSCode).Unique(); * map.Map(x => x.State).CustomType<int>(); * }) * //.Override<NModel.Supplier>(map => * //{ * // map.Map(x => x.Code).Unique(); * //}) * ) * )*/ m => m.FluentMappings.AddFromAssemblyOf <NModel.Mapping.ProductMap>()) .ExposeConfiguration(BuildSchema) .BuildSessionFactory(); } return(_sessionFactory); }
private ISessionFactory getSessionFactory() { if (_sessionFactory == null) { MyAutoMappingConfiguration mappingCfg = new MyAutoMappingConfiguration(); MySQLConfiguration dataConfig = MySQLConfiguration.Standard .ShowSql() .ConnectionString(s => s.FromConnectionStringWithKey("conn")); _sessionFactory = Fluently.Configure() .Database(dataConfig) .Mappings( /*automampping can't work with override m => m.AutoMappings.Add(AutoMap.AssemblyOf<NModel.Product>(mappingCfg) .Conventions.Setup(c=>{ c.Add<DefaultStringLengthConvention>(); }) .Override<NModel.Product>(map => { map.Map(x => x.NTSCode).Unique(); map.Map(x => x.State).CustomType<int>(); }) //.Override<NModel.Supplier>(map => //{ // map.Map(x => x.Code).Unique(); //}) ) )*/ m => m.FluentMappings.AddFromAssemblyOf<NModel.Mapping.ProductMap>()) .ExposeConfiguration(BuildSchema) .BuildSessionFactory(); } return _sessionFactory; }