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();
 }
Beispiel #2
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();
            }
        }
Beispiel #3
0
		public void KeyManyToOneAndNormalizedPersister()
		{
			Configuration cfg = new Configuration();
			cfg
				.AddClass(typeof(BaseClass))
				.AddClass(typeof(KeyManyToOneClass))
				.BuildSessionFactory().Close();
		}
        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");
        }
        static DataAccesser()
        {
            //NHibernate's Config Initialize
            config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.AddClass(typeof(Computer));

            //SessionFactory Initialize
            sessionFactory = config.BuildSessionFactory();
        }
Beispiel #6
0
        static DataAccesser()
        {
            //NHibernate's Config Initialize
            config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.AddClass(typeof(Computer));

            //SessionFactory Initialize
            sessionFactory = config.BuildSessionFactory();
        }
 private ISessionFactory CreateSessionFactory(NHibernateUnitOfWorkFacilityConfig config)
 {
     Configuration cfg = new Configuration().Configure(config.NHibernateConfigurationFile);
     foreach (Type mappedEntity in config.Entities) 
         cfg.AddClass(mappedEntity);
     
     ISessionFactory sessionFactory = cfg.BuildSessionFactory();
     EntitiesToRepositories.Register(Kernel, sessionFactory, typeof(NHRepository<>), config.IsCandidateForRepository);
     return sessionFactory;
 }
 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));
 }
		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);
			}
		}
Beispiel #10
0
 private void InitSessionFactory(Type classType)
 {
     if (sessionFactory == null)
         {
             Configuration config = new Configuration();
             config.AddClass(classType);
             sessionFactory = config.BuildSessionFactory();
             if (sessionFactory == null)
             {
                 return;
             }
         }
 }
Beispiel #11
0
        public void FixtureSetup()
        {
            BasicConfigurator.Configure();
            var cfg = new Configuration();
            cfg.AddProperties(new Dictionary<string, string> {
                {Environment.ConnectionProvider, typeof(DriverConnectionProvider).FullName},
                {Environment.Dialect, typeof(SQLiteDialect).FullName},
                {Environment.ConnectionDriver, typeof(SQLite20Driver).FullName},
                {Environment.ConnectionString, "Data Source=test.db;Version=3;New=True;"},
                //{"connection.release_mode", "on_close"},
            });

            cfg.AddClass(typeof (Simple));
            new SchemaExport(cfg).Create(true, true);
            sessionFactory = cfg.BuildSessionFactory();
        }
Beispiel #12
0
        public void TestCreate()
        {
            //NHibernate.Impl.SessionFactoryImpl
            var config = new Configuration();
            config.Configure("DatabaseCreate.cfg.xml");

            //config.AddAssembly(typeof (IModel).Assembly);
            //config.AddAssembly(typeof (User).Assembly);
            config.AddClass(typeof (User));

            Log.Debug("��ʼ�����");
            //config.AddAssembly(typeof())
            var schem = new SchemaExport(config);

            //schem.Drop(true, true);
            schem.Create(true, true);
        }
		public void ManualConfiguration() 
		{
			//log4net.Config.DOMConfigurator.ConfigureAndWatch( new FileInfo("log4net.cfg.xml") ); //use xml file instead of config
			Configuration cfg = new Configuration();
			IDictionary props = new Hashtable();

			props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider"; 
			props["hibernate.dialect" ] = "NHibernate.Dialect.MsSql2000Dialect"; 
			props["hibernate.connection.driver_class" ] = "NHibernate.Driver.SqlClientDriver" ;
			props["hibernate.connection.connection_string"] = "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) );

			new SchemaExport( cfg ).Create( true, true );

			ISessionFactory factory = cfg.BuildSessionFactory();

		}
        /// <summary>
        ///
        /// </summary>
        /// <param name="properties"></param>
        /// <param name="resources"></param>
        public void Configure(NameValueCollection properties, IDictionary resources)
        {
            string mapping = string.Empty;

            try
            {
                NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();

                // Set the connection string retrieve on the datasource
                config.SetProperty(CONNECTION_STRING, (resources["DataSource"] as DataSource).ConnectionString);

                foreach (DictionaryEntry entry in resources)
                {
                    if ((entry.Key.ToString()).StartsWith("class."))
                    {
                        config.AddClass(Resources.TypeForName(entry.Value.ToString()));
                    }
                    if ((entry.Key.ToString()) == "mapping")
                    {
                        mapping = entry.Value.ToString();
                    }

                    config.SetProperty(entry.Key.ToString(), entry.Value.ToString());
                }

                if (mapping.Length > 0)
                {
                    config.AddAssembly(mapping);
                }
                _factory = config.BuildSessionFactory();
            }
            catch (Exception e)
            {
                throw new ConfigurationException(string.Format("DaoManager could not configure NHibernateDaoSessionHandler. Cause: {0}", e.Message), e);
            }
        }
		public void Configure()
		{
			Configuration cfg = new Configuration();
			cfg.AddClass(typeof(Blog));
			cfg.AddClass(typeof(BlogItem));
			_sessions = cfg.BuildSessionFactory();
		}
        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));
            }
        }
Beispiel #17
0
        public void TestCreate()
        {
            //NHibernate.Impl.SessionFactoryImpl
            var config = new Configuration();
            config.Configure("DatabaseCreate.cfg.xml");

            config.AddAssembly(typeof(IModel).Assembly);
            config.AddAssembly(typeof(User).Assembly);

            config.AddAssembly(typeof(Bootstrap).Assembly);
            config.AddAssembly(typeof(DESEncrypt).Assembly);
            config.AddAssembly(typeof(JsonResult).Assembly);
            //config.AddClass(typeof (UserPhoto));
            //config.AddClass(typeof (User));
            //config.AddAssembly(typeof (IModel).Assembly);
            //config.AddAssembly(typeof (User).Assembly);

            #region �û����ݱ�

            config.AddClass(typeof(UserPhoto));
            config.AddClass(typeof(User));
            config.AddClass(typeof(UserSetting));

            #endregion

            //Log.Debug("��ʼ�����");
            //config.AddAssembly(typeof())
            var schem = new SchemaExport(config);

            //schem.Drop(true, true);
            schem.Create(true, true);
        }
		public void ExportTables()
		{
			Configuration cfg = new Configuration();
			cfg.AddClass(typeof(Blog));
			cfg.AddClass(typeof(BlogItem));
			new SchemaExport (cfg).Create(true,true);
		}
Beispiel #19
0
		private Configuration CreateConfiguration()
		{
			Configuration configuration = new Configuration();

			Configure(configuration);

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

			ApplyCacheSettings(configuration);

			return configuration;
		}