public void AddDataBaseIntegrationInfo(global::NHibernate.Cfg.Configuration config)
 {
     config.DataBaseIntegration(db =>
     {
         db.ConnectionString = string.Format("Data Source={0};Version=3;New=True;", _dbPath);
         db.Driver <SQLite20Driver>();
         db.Dialect <SQLiteDialect>();
         db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
         // enabled for testing
         db.LogFormattedSql = true;
         db.LogSqlInConsole = true;
         db.AutoCommentSql  = true;
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Configures NHibernate.
        /// </summary>
        /// <returns>
        /// The NHibernate configuration.
        /// </returns>
        private global::NHibernate.Cfg.Configuration Configure()
        {
            var configuration = new global::NHibernate.Cfg.Configuration();

            configuration.DataBaseIntegration(
                db =>
            {
                db.Driver <SQLite20Driver>();
                db.ConnectionString = "Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1";
                db.Dialect <SQLiteDialect>();
                db.ConnectionReleaseMode = ConnectionReleaseMode.OnClose;
            });

            return(configuration);
        }
        private static global::NHibernate.Cfg.Configuration BuildConfiguration(Action <IDbIntegrationConfigurationProperties> configureAction)
        {
            var cfg = new global::NHibernate.Cfg.Configuration();

            cfg.DataBaseIntegration(db =>
            {
                configureAction(db);
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                db.IsolationLevel     = IsolationLevel.ReadCommitted;
            });

            cfg.SetProperty("hbm2ddl.auto", "create");

            return(cfg.AddConfigurationMappings());
        }
Exemplo n.º 4
0
        public ISessionFactory GetSessionFactory(string connectionString, bool isDebug)
        {
            var configure = new global::NHibernate.Cfg.Configuration();

            configure.DataBaseIntegration(db =>
            {
                db.ConnectionString = connectionString;
                db.Driver <Driver.OracleDataClientDriver>();
                db.Dialect <global::NHibernate.Dialect.Oracle10gDialect>();
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                db.LogFormattedSql    = isDebug;
                db.LogSqlInConsole    = isDebug;
                db.AutoCommentSql     = false;
            });
            return(configure.BuildSessionFactory());
        }
Exemplo n.º 5
0
        public static ISessionFactory GetSessionFactory(HibernateDataContext cotnext)
        {
            var cfg = new global::NHibernate.Cfg.Configuration();

            cfg.DataBaseIntegration(c =>
            {
                c.ConnectionStringName = cotnext.ConnectionString;
                if (cotnext.Provider != null && cotnext.Provider.Equals("System.Data.SqlServerCe.4.0", StringComparison.OrdinalIgnoreCase))
                {
                    c.Driver <SqlServerCeDriver>();
                    c.Dialect <MsSqlCe40Dialect>();
                }
                else
                {
                    c.Driver <SqlClientDriver>();
                    c.Dialect <MsSql2008Dialect>();
                }

                #if DEBUG
                c.LogFormattedSql = true;
                #endif
                c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                c.SchemaAction       = SchemaAutoAction.Update;
            });

            var mapper = new ModelMapper();
            MapModels(mapper, cotnext.DbContext);
            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
            var result = cfg.BuildSessionFactory();
            if (cotnext.BuildSchema)
            {
                BuildSchema(cfg);
            }

            if (cotnext.UpdateSchema)
            {
                UpdateSchema(cfg);
            }
            return(result);
        }
Exemplo n.º 6
0
        private global::NHibernate.Cfg.Configuration CreateConfiguration()
        {
            var configuration = new global::NHibernate.Cfg.Configuration()
                .CurrentSessionContext<LazySessionContext>();

            configuration.DataBaseIntegration(db =>
            {
                db.ConnectionProvider<DriverConnectionProvider>();
                db.Dialect<MsSql2005Dialect>();
                db.Driver<SqlClientDriver>();
                db.ConnectionStringName = "default";
                db.BatchSize = 30;
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                db.Timeout = 10;
                db.LogFormattedSql = true;
                db.LogSqlInConsole = false;
                db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";
            });

            configuration.AddDeserializedMapping(EntitiesMapper.CreateMappingConfiguration(), "Cronos"); ;

            return configuration;
        }
Exemplo n.º 7
0
        private global::NHibernate.Cfg.Configuration CreateConfiguration()
        {
            var configuration = new global::NHibernate.Cfg.Configuration()
                                .CurrentSessionContext <LazySessionContext>();

            configuration.DataBaseIntegration(db =>
            {
                db.ConnectionProvider <DriverConnectionProvider>();
                db.Dialect <MsSql2005Dialect>();
                db.Driver <SqlClientDriver>();
                db.ConnectionStringName = "default";
                db.BatchSize            = 30;
                db.KeywordsAutoImport   = Hbm2DDLKeyWords.AutoQuote;
                db.Timeout               = 10;
                db.LogFormattedSql       = true;
                db.LogSqlInConsole       = false;
                db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";
            });

            configuration.AddDeserializedMapping(EntitiesMapper.CreateMappingConfiguration(), "Cronos");;

            return(configuration);
        }
Exemplo n.º 8
0
        //[Fact]
        public async Task ConstructDynamicEntity_Test()
        {
            try
            {
                const string firstNamePropName = "FirstName";

                var dynamicEntityMeta = new DynamicEntity
                {
                    Name       = "DynamicPerson",
                    Properties = new DynamicPropertyList
                    {
                        { "Id", typeof(Guid) },
                        { firstNamePropName, typeof(string) },
                        { "LastName", typeof(string) },
                        { "Age", typeof(int) },
                        { "BirthDate", typeof(DateTime?) },
                    }
                };

                var dynamicPersonType = ShaEntityTypeBuilder.CompileResultType(dynamicEntityMeta);
                var dynamicPerson     = Activator.CreateInstance(dynamicPersonType);

                dynamicPerson.ShouldNotBeNull();

                var firstNameTestValue = "John";
                var propInfo           = dynamicPerson.GetType().GetProperty(firstNamePropName);
                propInfo.SetValue(dynamicPerson, firstNameTestValue);

                var firstNameValue = propInfo.GetValue(dynamicPerson);

                firstNameValue.ShouldBe(firstNameTestValue);

                var nhConfig = new global::NHibernate.Cfg.Configuration();
                nhConfig.DataBaseIntegration(db =>
                {
                    db.ConnectionString = @"Data Source=.\sql2019;Initial Catalog=SheshaDemo;Integrated Security=True";

                    db.Dialect <MsSql2012Dialect>();
                    db.Driver <Sql2008ClientDriver>();
                    db.Timeout         = 150;
                    db.LogFormattedSql = true;
                })
                .SetProperty("hbm2ddl.keywords", "auto-quote")
                .CurrentSessionContext <UnitOfWorkSessionContext>();

                // register filters
                nhConfig.AddFilterDefinition(SoftDeleteFilter.GetDefinition());
                nhConfig.AddFilterDefinition(MayHaveTenantFilter.GetDefinition());
                nhConfig.AddFilterDefinition(MustHaveTenantFilter.GetDefinition());

                var conventions           = new Conventions();
                var dynamicPersonAssembly = dynamicPerson.GetType().Assembly;
                conventions.AddAssembly(dynamicPersonAssembly, "Test_");
                conventions.Compile(nhConfig);

                var sessionFactory = nhConfig.BuildSessionFactory();

                var migrationsGenerator = LocalIocManager.Resolve <IMigrationGenerator>();
                var migration           = migrationsGenerator.GenerateMigrations(new List <Type> {
                    dynamicPersonType
                });

                using (var session = sessionFactory.OpenSession())
                {
                    // save our person
                    session.SaveOrUpdate(dynamicPerson);
                    session.Flush();
                    var person = dynamicPerson as Entity <Guid>;
                    person.ShouldNotBeNull();
                    person.Id.ShouldNotBe(Guid.Empty);

                    var query = session.CreateQuery($"select ent from {dynamicPersonType.FullName} ent");
                    var items = query.List();
                    items.Count.ShouldBeGreaterThan(0);

                    var fetchedPerson = session.Get(dynamicPersonType, person.Id) as Entity <Guid>;
                    fetchedPerson.ShouldNotBeNull();
                    fetchedPerson.Id.ShouldBe(person.Id);
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
		/// <summary>
		/// Configures NHibernate.
		/// </summary>
		/// <returns>
		/// The NHibernate configuration.
		/// </returns>
		private global::NHibernate.Cfg.Configuration Configure()
		{
			var configuration = new global::NHibernate.Cfg.Configuration();

			configuration.DataBaseIntegration(
				db =>
					{
						db.Driver<SQLite20Driver>();
						db.ConnectionString = "Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1";
						db.Dialect<SQLiteDialect>();
						db.ConnectionReleaseMode = ConnectionReleaseMode.OnClose;
					});

			return configuration;
		}