public static ISession OpenSession()
        {
            var configuration     = new Configuration();
            var configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\hibernate.cfg.xml");

            configuration.Configure(configurationPath);
            var bookConfigurationFile = HttpContext.Current.Server.MapPath(@"~\Models\Mapping\Book.hbm.xml");

            configuration.AddFile(bookConfigurationFile);
            ISessionFactory  sessionFactory = configuration.BuildSessionFactory();
            DatabaseMetadata meta           = new DatabaseMetadata((DbConnection)sessionFactory.OpenSession().Connection, new NHibernate.Dialect.MsSql2008Dialect());

            if (meta.IsTable("Book"))
            {
                Debug.WriteLine("Book ada");
            }
            else
            {
                Debug.WriteLine("Book tidak ada");
                new SchemaUpdate(configuration).Execute(true, true);
            }


            return(sessionFactory.OpenSession());
        }
Beispiel #2
0
            public override bool IsTableInDatabase(Type type)
            {
                var name = type.Name;

                using (var session = GetSessionFactory().OpenSession())
                {
                    var meta = new DatabaseMetadata(session.Connection, new global::NHibernate.Dialect.MsSql2012Dialect());
                    //TABLE_NAME e.g. "hibernate_unique_key"
                    return(meta.IsTable(name));
                }
            }
        private Boolean existeTablaMEFMaster(ISession sesion, String tabla)
        {//JSA01
            Boolean existeTabla = false;
            Boolean continuar   = true;

            var a = sesion.GetSessionImplementation().Factory.OpenSession();
            DatabaseMetadata meta = new DatabaseMetadata((DbConnection)a.Connection, new NHibernate.Dialect.MsSql2012Dialect());

            if (meta.IsTable(tabla))
            {
                existeTabla = true;
            }
            return(existeTabla);
        }