コード例 #1
0
        public void CreateDao(bool secondLevelCache)
        {
            Configuration configuration = new Configuration();

            configuration.SetNamingStrategy(ImprovedNamingStrategy.Instance);
            configuration.Properties = (IDictionary <string, string>)CreateProperties(secondLevelCache);
            configuration.AddClass(typeof(VocabularyDomain));
            configuration.AddClass(typeof(CodeSystem));
            configuration.AddClass(typeof(CodedValue));
            configuration.AddClass(typeof(ValueSet));
            configuration.AddClass(typeof(ValueSetEntry));

            this.factory = configuration.BuildSessionFactory();
            this.dao     = new HibernateCodeSetDao(this.factory);
        }
コード例 #2
0
 private void AddEntities()
 {
     foreach (var type in EntityTypes)
     {
         configuration.AddClass(type);
     }
 }
コード例 #3
0
        private static void Main()
        {
            // log4net Config
            XmlConfigurator.Configure();

            // NHibernate Config
            try {
                Configuration cfg = new Configuration();
//				log.Info("Mapping Foo");
//				cfg.AddClass(typeof (Foo));
                log.Info("Mapping Bar");
                cfg.AddClass(typeof(Bar));

                ISessionFactory factory = cfg.BuildSessionFactory();
                ISession        session = factory.OpenSession();

//				Foo foo = new Foo();
//				foo.Nombre = "Foo" + DateTime.Now.Millisecond;
                Bar bar = new Bar();
                bar.Nombre = "Bar" + DateTime.Now.Millisecond;

                //foo.Bar = bar;
                //bar.Foo = foo;

                //session.Save(foo);

                bar.Id = 33;
                session.Update(bar);
            } catch (Exception ex) {
                Console.WriteLine(ex);
            } finally {
                Console.ReadLine();
            }
        }
        public When_using_custom_bytecode_provider()
        {
            //register the bytecode provider with NHibernate
            Initializer.RegisterBytecodeProvider(new EntityInjector());
            //configure NHibernate
            var config = new Configuration();

            config.AddClass(typeof(BasicCat));
            config.AddClass(typeof(InterfaceCat));
            config.AddClass(typeof(DependencyInjectionCat));
            //create the database
            var tool = new SchemaExport(config);

            tool.Execute(false, true, false);
            //build the session factory
            _sessionFactory = config.BuildSessionFactory();
        }
コード例 #5
0
        public void SystemTypeForDocumentId()
        {
            Configuration tempCfg = new Configuration();

            tempCfg.Configure();
            tempCfg.SetProperty("hibernate.search.default.directory_provider", typeof(RAMDirectoryProvider).AssemblyQualifiedName);
            tempCfg.AddClass(typeof(Gangster));
            Assert.Throws <HibernateException>(() => tempCfg.BuildSessionFactory(), "Unable to guess IFieldBridge for Id");
        }
コード例 #6
0
        public async Task KeyManyToOneAndNormalizedPersisterAsync()
        {
            Configuration cfg = new Configuration();

            await(cfg
                  .AddClass(typeof(BaseClass))
                  .AddClass(typeof(KeyManyToOneClass))
                  .BuildSessionFactory().CloseAsync());
        }
コード例 #7
0
ファイル: NHibernateHelper.cs プロジェクト: EveYan/agile
        private ISessionFactory GetSessionFactory(Type type)
        {
            Configuration config = new Configuration();

            config.AddClass(type);
            ISessionFactory iSess = config.Configure().BuildSessionFactory();

            return(iSess);
        }
コード例 #8
0
        public void KeyManyToOneAndNormalizedPersister()
        {
            Configuration cfg = new Configuration();

            cfg
            .AddClass(typeof(BaseClass))
            .AddClass(typeof(KeyManyToOneClass))
            .BuildSessionFactory().Close();
        }
コード例 #9
0
        /// <summary>
        /// Applies any added mappings to the NHibernate Configuration
        /// </summary>
        /// <param name="cfg">NHibernate Configuration instance</param>
        internal void Apply(Configuration cfg)
        {
            foreach (var persistentClass in classes)
            {
                cfg.AddClass(persistentClass);
            }

            foreach (var assembly in assemblies)
            {
                cfg.AddAssembly(assembly);
            }
        }
コード例 #10
0
        private static ISession GenerateSession()
        {
            var cfg = new Configuration()
                      .AddProperties(new Dictionary <string, string>
            {
                { Environment.ConnectionDriver, typeof(SQLite20Driver).FullName },
                { Environment.Dialect, typeof(SQLiteDialect).FullName },
                { Environment.ConnectionProvider, typeof(DriverConnectionProvider).FullName },
                { Environment.ConnectionString, GetConnectionString() },
                { Environment.QuerySubstitutions, "true=1;false=0" },
                { Environment.ShowSql, "false" }
            });

            cfg.AddClass(typeof(DtoFileInfo));
            cfg.AddClass(typeof(DtoLog));
            cfg.AddClass(typeof(DtoRegistryKey));
            cfg.AddClass(typeof(DtoRegistryValue));
            cfg.AddClass(typeof(DtoServiceInfo));
            cfg.AddClass(typeof(DtoUserSettings));

            var sessions = cfg.BuildSessionFactory();

            _session = sessions.OpenSession();
            return(_session);
        }
コード例 #11
0
        public void ClassMissingMappingFile()
        {
            Configuration cfg = new Configuration();

            try
            {
                cfg.AddClass(typeof(A));
            }
            catch (MappingException me)
            {
                Assert.AreEqual("Resource not found: " + typeof(A).FullName + ".hbm.xml", me.Message);
            }
        }
コード例 #12
0
        public When_using_session_auditor()
        {
            //configure NHibernate
            var config = new Configuration();

            config.AddClass(typeof(Cat));
            //create the database
            var tool = new SchemaExport(config);

            tool.Execute(false, true, false);
            //initialize context
            _currentScope = new Marshaler(config, typeof(ValidationInterceptor));
        }
コード例 #13
0
        private ISessionFactory CreateSessionFactory(NHibernateUnitOfWorkFacilityConfig config)
        {
            var cfg = new Configuration().Configure(config.NHibernateConfigurationFile);

            foreach (var mappedEntity in config.Entities)
            {
                cfg.AddClass(mappedEntity);
            }

            var sessionFactory = cfg.BuildSessionFactory();

            EntitiesToRepositories.Register(Kernel, sessionFactory, typeof(NHRepository <>), config.IsCandidateForRepository);
            return(sessionFactory);
        }
コード例 #14
0
        private Configuration CreateConfiguration()
        {
            Configuration configuration = new Configuration();

            Configure(configuration);

            foreach (Type type in this.Mappings)
            {
                configuration.AddClass(type);
            }

            ApplyCacheSettings(configuration);

            return(configuration);
        }
コード例 #15
0
ファイル: Fixture.cs プロジェクト: jrauber/GH1429
 public Task KeyManyToOneAndNormalizedPersisterAsync()
 {
     try
     {
         Configuration cfg = new Configuration();
         return(cfg
                .AddClass(typeof(BaseClass))
                .AddClass(typeof(KeyManyToOneClass))
                .BuildSessionFactory().CloseAsync());
     }
     catch (Exception ex)
     {
         return(Task.FromException <object>(ex));
     }
 }
コード例 #16
0
        private void InitializeIOC()
        {
            NHibernateUnitOfWorkFacilityConfig[] configs = CreateRules();
            IoC.Initialize(
                new WindsorContainer()
                .AddFacility("Multiple.Units.Of.Work", new MultipleNHibernateUnitOfWorkFacility(configs)));

            //load schemas to create databases
            schemas = new List <SchemaExport>();
            foreach (NHibernateUnitOfWorkFacilityConfig config in configs)
            {
                Configuration cfg = new Configuration().Configure(config.NHibernateConfigurationFile);
                foreach (Type entity in config.Entities)
                {
                    cfg.AddClass(entity);
                }
                schemas.Add(new SchemaExport(cfg));
            }
        }
コード例 #17
0
        private ISessionFactory CreateSessionFactory()
        {
            Configuration cfg;

            cfg = new Configuration().Configure();

            foreach (var t in types)
            {
                cfg.AddClass(t);
            }

            cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, this.ConnectionString);

#if DEBUG
            cfg.SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true");
            cfg.SetProperty(NHibernate.Cfg.Environment.ShowSql, "true");
#endif
            new SchemaExport(cfg).Execute(true, true, false);
            return(cfg.BuildSessionFactory());
        }
コード例 #18
0
        public async Task ManualConfigurationAsync()
        {
            //log4net.Config.DOMConfigurator.ConfigureAndWatch( new FileInfo("log4net.cfg.xml") ); //use xml file instead of config
            Configuration cfg   = new Configuration();
            IDictionary   props = new Hashtable();

            props[Environment.ConnectionProvider] = "NHibernate.Connection.DriverConnectionProvider";
            props[Environment.Dialect]            = "NHibernate.Dialect.MsSql2000Dialect";
            props[Environment.ConnectionDriver]   = "NHibernate.Driver.SqlClientDriver";
            props[Environment.ConnectionString]   =
                "Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI";

            foreach (DictionaryEntry de in props)
            {
                cfg.SetProperty(de.Key.ToString(), de.Value.ToString());
            }

            cfg.AddClass(typeof(Simple));

            await(new SchemaExport(cfg).CreateAsync(true, true));

            ISessionFactory factory = cfg.BuildSessionFactory();
        }
コード例 #19
0
        private void InitSessionFactory()
        {
            // sessionFactory = new Configuration().Configure().SetProperty(NHibernate.Cfg.Environment.ConnectionString).BuildSessionFactory();
            //"Server=FATIH;Initial Catalog=HAN2009;Password=sapass;User ID=sa"
            //    public InMemoryDatabaseTest(Assembly assemblyContainingMapping)
            //{
            //  if (Configuration == null)
            //  {
            //    Configuration = new Configuration()
            //      .SetProperty(Environment.ReleaseConnections,"on_close")
            //      .SetProperty(Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
            //      .SetProperty(Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName)
            //      .SetProperty(Environment.ConnectionString, "data source=:memory:")
            //      .SetProperty(Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName)
            //      .AddAssembly(assemblyContainingMapping);

            //    SessionFactory = Configuration.BuildSessionFactory();
            //  }

            //  session = SessionFactory.OpenSession();

            //  new SchemaExport(Configuration).Execute(true, true, false, true, session.Connection, Console.Out);
            //}
            //    <session-factory>
            //  <property name="show_sql">true</property>
            //  <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
            //  <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
            //  <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
            //  <property name="connection.connection_string">Server=FATIH;Initial Catalog=HAN2009;Password=sapass;User ID=sa</property>
            //  <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
            //  <mapping assembly="Indeks.Data"/>

            //  <!-- NHibernate 2.1 -->


            //</session-factory>
//      Configuration cfg = new Configuration()
//    .addResource("Item.hbm.xml")
//    .addResource("Bid.hbm.xml");
//An alternative way is to specify the mapped class and allow Hibernate to find the mapping document for you:

//Configuration cfg = new Configuration()
//    .addClass(org.hibernate.auction.Item.class)
//    .addClass(org.hibernate.auction.Bid.class);
            Stopwatch     sw  = Stopwatch.StartNew();
            Configuration con = new Configuration();

            con.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
            con.SetProperty(Env.Dialect, "NHibernate.Dialect.MsSql2005Dialect");
            con.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
            con.SetProperty(Env.ConnectionString, DataBaseInfo.ConString);
            con.SetProperty(Env.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
            //con.SetProperty(Env.DefaultSchema,"HAN2009");
            con.AddClass(typeof(Sube));//.AddAssembly("Indeks.Data");
            //con.SetProperty(Env.PropertyBytecodeProvider, "NHibernate.ByteCode.Castle");
            //con.SetProperty(Env., "NHibernate.ByteCode.Castle");

            sessionFactory = con.BuildSessionFactory();
            int a = sw.Elapsed.Milliseconds;

            a = 3;
            //sessionFactory = Fluently.Configure()

            //                     .Database(MsSqlConfiguration.MsSql2005
            //                     .ConnectionString(c => c
            //                     .Is(DataBaseInfo.ConString))
            //                     .Dialect("NHibernate.Dialect.MsSql2005Dialect").Provider("NHibernate.Connection.DriverConnectionProvider")
            //                     .Driver("NHibernate.Driver.SqlClientDriver")
            //                     .DefaultSchema("HAN2009")
            //                     .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")
            //                     .ShowSql())
            //                     .Mappings(m=>m.HbmMappings.AddClasses(typeof(Sube)))
            //                     .BuildSessionFactory();

            //Configuration cfg = null;
            //IFormatter serializer = new BinaryFormatter();

            ////first time
            //cfg = new Configuration().Configure();

            //using (Stream stream = File.OpenWrite("Configuration.serialized"))
            //{
            //  serializer.Serialize(stream, configuration);
            //}

            ////other times
            //using (Stream stream = File.OpenRead("Configuration.serialized"))
            //{
            //  cfg = serializer.Deserialize(stream) as Configuration;
            //}
        }