public virtual void Configure(Configuration cfg)
        {
            EnsureMappingsBuilt();

            foreach (var mapping in compiledMappings.Where(m => !m.Classes.Any()))
            {
                var         serializer = new MappingXmlSerializer();
                XmlDocument document   = serializer.Serialize(mapping);
                cfg.AddDocument(document);
            }

            foreach (var mapping in compiledMappings.Where(m => m.Classes.Any()))
            {
                var         serializer = new MappingXmlSerializer();
                XmlDocument document   = serializer.Serialize(mapping);

                if (cfg.GetClassMapping(mapping.Classes.First().Type) == null)
                {
                    cfg.AddDocument(document);
                }
            }
        }
Esempio n. 2
0
        internal NhibernateSessionFactory(Assembly[] assemblyArray, DBSwitch dbswitch)
        {
            if (dbswitch.ConnectionString == null)
            {
                throw new NotImplementedException("Hibernate Connection String is NULL");
            }

            Configuration cfg = new Configuration();

            cfg.Configure();

            cfg.SetProperty("connection.connection_string", dbswitch.ConnectionString);

            HibernateConfigGenerator gen = new HibernateConfigGenerator(dbswitch.ConnectStringRef);

            var assemblyList = new List <Assembly>();

            assemblyList.Add(typeof(Entity).Assembly);
            assemblyList.AddRange(assemblyArray);

            foreach (Assembly assembly in assemblyList)
            {
                var    xmlConfig           = gen.Generate(assembly);
                string hibernateXmlFileDir = "";
                string path = @"D:\";
                if (Directory.Exists(path))
                {
                    hibernateXmlFileDir = QCFileLogger.LogRootDirFirst + @"\Log_HibernateConfigFiles";
                }
                else
                {
                    hibernateXmlFileDir = QCFileLogger.LogRootDir + @"\Log_HibernateConfigFiles";
                }

                //string hibernateXmlFileDir = QCFileLogger.LogRootDir + @"\Log_HibernateConfigFiles";
                Directory.CreateDirectory(hibernateXmlFileDir);
                string configFilePath = hibernateXmlFileDir + @"\" + dbswitch.ConnectStringRef + "_" + assembly.GetName().Name
                                        + "_" + DateTime.Now.ToString().Replace("/", "-").Replace(":", "_").Replace(" ", "_") + ".hbm.xml";
                StreamWriter writer = new StreamWriter(configFilePath);
                writer.Write(xmlConfig);
                writer.Close();

                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(xmlConfig);

                cfg.AddDocument(xdoc);
            }


            SessionFactory = cfg.BuildSessionFactory();
        }
Esempio n. 3
0
        protected override void AddMappings(Configuration configuration)
        {
            var xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"NHibernate.Test.VersionTest.Db\" assembly=\"NHibernate.Test\"><class name=\"ProductWithVersionAndLazyProperty\"><id name=\"Id\" generator=\"assigned\"/><version name=\"Version\" generated=\"always\" unsaved-value=\"null\" type=\"BinaryBlob\" access=\"nosetter.camelcase-underscore\"><column name=\"version\" not-null=\"false\" sql-type=\"timestamp\" /></version><property name=\"Summary\" lazy=\"true\"/></class></hibernate-mapping>";
            var doc = new XmlDocument();

            doc.LoadXml(xml);

            configuration.AddDocument(doc);

            base.AddMappings(configuration);

            configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, SchemaAutoAction.Recreate.ToString());
            configuration.SetProperty(NHibernate.Cfg.Environment.FormatSql, Boolean.TrueString);
            configuration.SetProperty(NHibernate.Cfg.Environment.ShowSql, Boolean.TrueString);
        }
Esempio n. 4
0
        public void AddDocument()
        {
            string hbm =
                @"<?xml version='1.0' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
	<class name='NHibernate.DomainModel.A, NHibernate.DomainModel'>
		<id name='Id' column='somecolumn'>
			<generator class='native' />
		</id>
	</class>
</hibernate-mapping>";

            Configuration cfg = new Configuration();
            XmlDocument   doc = new XmlDocument();

            doc.LoadXml(hbm);
            cfg.AddDocument(doc);
        }