コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }