public static void GenerateSchema()
        {
            Configuration cfg = new Configuration();

            //cfg.SetProperty("nhibernate.envers.default_schema", "audit");

            cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));

            var mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

            HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
            cfg.AddMapping(mapping);

            cfg.AddAssembly(typeof(Model).Assembly);

            //cfg.IntegrateWithEnvers();

            cfg.Configure();

            new NHibernate.Tool.hbm2ddl.SchemaExport(cfg)
                .SetDelimiter(";")
                //.SetOutputFile("schema.sql")
                .Execute(false, true, false);
        }
        static void Main(string[] args)
        {
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            var mapper = new ConventionModelMapper();

            mapper.Class<SomeAreaClass>(c =>
            {
                c.Property(x => x.Area, m =>
                {
                    m.Type<MsSql2008GeographyType>();
                    m.NotNullable(true);
                });
            });

            var cfg = new Configuration()

                .DataBaseIntegration(db =>
                {
                    db.ConnectionString = "YourConnectionString";
                    db.Dialect<MsSql2012GeographyDialect>();
                });

            cfg
                .AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            cfg
                .AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));

            new SchemaExport(cfg).Execute(false, true, false);
        }
        public static void Bootstrap()
        {
            var orm = MapConfiguration.GetObjectRelationalMapper();

            _mappings = MapConfiguration.GetMapings(orm);
            _configuration = GetConfiguration(_mappings);
            _configuration.AddAuxiliaryDatabaseObject(CreateHighLowScript(orm));
            SessionFactory = _configuration.BuildSessionFactory();

            _connection = MapConfiguration.BuildSchema(SessionFactory.OpenSession(), _configuration);

        }
        public static void Bootstrap()
        {
            _configuration = Fluently.Configure()
                    .Database(MsSqlCeConfiguration.Standard.ConnectionString(c => c.FromConnectionStringWithKey("FailTrackerData")))
                    .Mappings(m => m.AutoMappings.Add(
                    AutoMap.AssemblyOf<Issue>(new FailTrackerConfig()).UseOverridesFromAssemblyOf<IssueOverrides>()
                    )
                )
                .BuildConfiguration();
            _configuration.AddAuxiliaryDatabaseObject(new SimpleAuxiliaryDatabaseObject("alter table UserToProject add constraint PK_UserToProject primary key (User_id, Project_id)", ""));

            _sessionFactory = _configuration.BuildSessionFactory();
        }
        static FactoryProvider()
        {
            var modelInspector = new MySimpleModelInspector();
            Assert.IsNotNull(new Entity());
            var mapper = new ModelMapper(modelInspector);
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
            mapper.BeforeMapClass += (mi, type, map) =>
                                     map.Id(idmap => idmap.Generator(Generators.HighLow,
                                                                     gmap => gmap.Params(new
                                                                                         	{
                                                                                         		table = "NextHighVaues",
                                                                                         		column = "NextHigh",
                                                                                         		max_lo = 100,
                                                                                         		where = String.Format("EntityName = '{0}'", type.Name.ToLowerInvariant())
                                                                                         	})));
            mapper.BeforeMapClass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant());
            mapper.BeforeMapJoinedSubclass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant());
            mapper.BeforeMapUnionSubclass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant());

            mapper.BeforeMapProperty += (mi, propertyPath, map) =>
                                            {
                                                if (typeof(decimal).Equals(propertyPath.LocalMember.GetPropertyOrFieldType()))
                                                {
                                                    map.Type(NHibernateUtil.Currency);
                                                }
                                            };
            mapper.BeforeMapBag += (mi, propPath, map) =>
                                   	{
                                   		map.Cascade(Cascade.All.Include(Cascade.DeleteOrphans));
                                   		map.BatchSize(10);
                                   	};
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
            var domainMapping = mapper.CompileMappingForEachExplicitlyAddedEntity();
            domainMapping.WriteAllXmlMapping();
            var configuration = new Configuration();
            configuration.DataBaseIntegration(c =>
                                              	{
                                              		c.Dialect<MsSql2008Dialect>();
                                              		c.ConnectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=IntroNH;Integrated Security=True;Pooling=False";
                                              		c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                                              		c.SchemaAction = SchemaAutoAction.Create;
                                              	});
            foreach(var mapping in domainMapping)
            {
                configuration.AddMapping(mapping);
            }
            configuration.AddAuxiliaryDatabaseObject(CreateHighLowScript(modelInspector, Assembly.GetExecutingAssembly().GetExportedTypes()));

            Factory=configuration.BuildSessionFactory();
        }
        public static void Bootstrap()
        {
            var stdConfig = new Configuration();
            stdConfig.Configure();
            stdConfig.AddAuxiliaryDatabaseObject(new SimpleAuxiliaryDatabaseObject("alter table UserToProject add constraint PK_UserToProject primary key (User_id, Project_id)", ""));

            _configuration = Fluently.Configure(stdConfig)
                .Mappings(m => m.AutoMappings.Add(
                    AutoMap.AssemblyOf<Issue>(new FailTrackerConfig()).UseOverridesFromAssemblyOf<IssueOverrides>()
                    )
                )
                .BuildConfiguration();

            _sessionFactory = _configuration.BuildSessionFactory();
        }
Beispiel #7
0
        public static void CreateHighLowTable(NHibernate.Cfg.Configuration config, HiloTable hiloTable)
        {
            StringBuilder stringBuilder1 = new StringBuilder();

            stringBuilder1.AppendFormat("DELETE FROM {0};", (object)hiloTable.Name);
            stringBuilder1.AppendLine();
            stringBuilder1.AppendFormat("ALTER TABLE {0} ADD {1} VARCHAR(128);", (object)hiloTable.Name, (object)hiloTable.TableNameColumn);
            stringBuilder1.AppendLine();
            StringBuilder stringBuilder2 = new StringBuilder();

            foreach (string str in Enumerable.Distinct <string>(Enumerable.Select <PersistentClass, string>(Enumerable.Where <PersistentClass>((IEnumerable <PersistentClass>)config.ClassMappings, (Func <PersistentClass, bool>)(m => m.IdentifierProperty.Type.ReturnedClass == typeof(long))), (Func <PersistentClass, string>)(m => m.Table.Name))))
            {
                stringBuilder2.AppendFormat(string.Format("INSERT INTO [{0}] ({1}, {2}) VALUES ('{3}', 1);", (object)hiloTable.Name, (object)hiloTable.TableNameColumn, (object)hiloTable.NextHiColumn, (object)str), new object[0]);
                stringBuilder2.AppendLine();
            }
            NHibernate.Cfg.Configuration configuration1 = config;
            string sqlCreateString1 = ((object)stringBuilder1).ToString();
            // ISSUE: variable of the null type

            HashedSet <string> hashedSet1 = new HashedSet <string>();

            hashedSet1.Add(typeof(MsSql2005Dialect).FullName);
            hashedSet1.Add(typeof(MsSql2008Dialect).FullName);
            hashedSet1.Add(typeof(MySQL5Dialect).FullName);
            hashedSet1.Add(typeof(SQLiteDialect).FullName);
            HashedSet <string>            dialectScopes1           = hashedSet1;
            SimpleAuxiliaryDatabaseObject auxiliaryDatabaseObject1 = new SimpleAuxiliaryDatabaseObject(sqlCreateString1, (string)"", dialectScopes1);

            configuration1.AddAuxiliaryDatabaseObject((IAuxiliaryDatabaseObject)auxiliaryDatabaseObject1);
            NHibernate.Cfg.Configuration configuration2 = config;
            string sqlCreateString2 = ((object)stringBuilder2).ToString();
            // ISSUE: variable of the null type

            HashedSet <string> hashedSet2 = new HashedSet <string>();

            hashedSet2.Add(typeof(MsSql2005Dialect).FullName);
            hashedSet2.Add(typeof(MsSql2008Dialect).FullName);
            hashedSet2.Add(typeof(MySQL5Dialect).FullName);
            hashedSet2.Add(typeof(SQLiteDialect).FullName);
            HashedSet <string>            dialectScopes2           = hashedSet2;
            SimpleAuxiliaryDatabaseObject auxiliaryDatabaseObject2 = new SimpleAuxiliaryDatabaseObject(sqlCreateString2, (string)"", dialectScopes2);

            configuration2.AddAuxiliaryDatabaseObject((IAuxiliaryDatabaseObject)auxiliaryDatabaseObject2);
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();
              var log = LogManager.GetLogger(typeof (Program));

              NHibernateProfiler.Initialize();

              var cfg = new Configuration().Configure();

              cfg.AddAuxiliaryDatabaseObject(
            new SpatialAuxiliaryDatabaseObject(cfg));

              var sessionFactory = cfg.BuildSessionFactory();

              //Houston, TX
              var houstonTX = new Point(-95.383056, 29.762778);

              using (var session = sessionFactory.OpenSession())
              {
            using (var tx = session.BeginTransaction())
            {
              var query = session.CreateCriteria(
            typeof (StatePart))
            .Add(SpatialExpression.Contains(
              "Geometry", houstonTX));
              var part = query.UniqueResult<StatePart>();
              if (part == null)
              {
            log.InfoFormat("Houston, we have a problem.");
              }
              else
              {
            log.InfoFormat("Houston is in {0}",
              part.Name);
              }
              tx.Commit();
            }
              }
        }