static NHibernateManager() { Configuration cfg= new Configuration().Configure(); //cfg.AddAssembly("App_SubCode_APAS"); //cfg.AddClass(typeof(Apas.Business.BCOtherFeeType)); //Business Persistent Entity Mappings cfg.AddDirectory(new System.IO.DirectoryInfo ( HttpContext.Current.Server.MapPath ( @"~/App_Code/APAS/Business/NHibernate Mappings/" ) ) ); //Security Layer Entity Mappings cfg.AddDirectory(new System.IO.DirectoryInfo ( HttpContext.Current.Server.MapPath ( @"~/App_Code/APAS/Security/NHibernate Mappings/" ) ) ); sessionFactory= cfg.BuildSessionFactory(); }
static void Main() { DbConnectionStringBuilder dcsBuilder = new DbConnectionStringBuilder(); dcsBuilder.Add("User ID", "wjzgis"); dcsBuilder.Add("Password", "wjzgis"); dcsBuilder.Add("Service Name", "sunz"); dcsBuilder.Add("Host", "172.16.1.9"); dcsBuilder.Add("Integrated Security", false); string licPath = Application.StartupPath + "\\DDTek.lic"; //dcsBuilder.Add("License Path", licPath); //若路径中存在空格,则会在路径名称前加上"\"" string conStr = dcsBuilder.ConnectionString; conStr = conStr.Replace("\"", ""); Configuration config = new Configuration(); config.AddDirectory(new System.IO.DirectoryInfo( System.IO.Path.Combine(Application.StartupPath, "DataMapping"))); config.Properties["connection.connection_string"] = conStr; NHibernate.ISessionFactory sFactory = config.BuildSessionFactory(); NHibernate.ISession session = sFactory.OpenSession(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
public void init() { cfg = new Configuration(); cfg.Configure(); /* Add xml mappings created manually * - Because Web Site projects are only compiled during runtime, the hibernate mapping files will need to * be discovered and added to the assembly at runtime. */ cfg.AddDirectory(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Mapping"))); //Add your custom configurations here to override the Hibernate.xml configuration. }
public static void InitHibernate() { Debug.WriteLine("Configuring Hibernate..."); Log.Info("hello"); var cfg = new Configuration(); HbmSerializer.Default.Validate = true; HbmSerializer.Default.Serialize(Environment.CurrentDirectory, Assembly.GetExecutingAssembly()); cfg.AddDirectory(new DirectoryInfo(Environment.CurrentDirectory)); var sessionFactory = cfg.Configure().BuildSessionFactory(); SessionFactory = sessionFactory; Debug.WriteLine("Created SessionFactory!"); }
public void init() { cfg = new Configuration(); cfg.Configure(); /* Add xml mappings created manually * - Because Web Site projects are only compiled during runtime, the hibernate mapping files will need to * be discovered and added to the assembly at runtime. */ //cfg.AddDirectory(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/App_Code"))); cfg.AddDirectory(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Mapping"))); //Add all classes //cfg.AddAssembly(typeof(UserAccount).Assembly); }
/// <summary> /// Method to create session and manage entities /// </summary> /// <returns></returns> ISession OpenSession() { if (sessionFactory == null) { var cgf = new Configuration(); var data = cgf.Configure("c:\\users\\matute\\documents\\visual studio 2015\\Projects\\NHibernate_Expo\\NHibernate_Expo\\Models\\NHibernate\\Configuration\\hibernate.cfg.xml"); cgf.AddDirectory(new System.IO.DirectoryInfo("c:\\users\\matute\\documents\\visual studio 2015\\Projects\\NHibernate_Expo\\NHibernate_Expo\\Models\\NHibernate\\Mappings")); //var data = cgf.Configure(HttpContext.Current.Server.MapPath(@"Models\NHibernate\Configuration\hibernate.cfg.xml")); //cgf.AddDirectory(new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath(@"Models\NHibernate\Mappings"))); sessionFactory = data.BuildSessionFactory(); } return sessionFactory.OpenSession(); }
public override DomainServiceDescriptionProvider CreateProvider(Type domainServiceType, DomainServiceDescriptionProvider parent) { string currentDir = AppDomain.CurrentDomain.BaseDirectory; Configuration cfg = null; try { cfg = new Configuration(); cfg.Configure(_nHibernateConfigurationPath); cfg.AddDirectory(new DirectoryInfo(currentDir)); } catch { throw; } return new NHibernateTypeDescriptionProvider(domainServiceType, parent, cfg); }
public Configuration Build() { Configuration cfg = LoadConfigurationFromFile(); if (cfg == null) { foreach (TelChina.AF.Sys.Configuration.AddElement item in AFConfigurationManager.PLGroup.Storages) { var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, item.FileName); cfg = new NHibernate.Cfg.Configuration(); cfg.Configure(fileName); //设置实体映射文件关联 var mappingFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CONFIGPATH); cfg.AddDirectory(new System.IO.DirectoryInfo(mappingFileName)); } SaveConfigurationToFile(cfg); } return cfg; }
/// <summary> /// Method to create session and manage entities /// </summary> /// <returns></returns> ISession OpenSession() { if (sessionFactory == null) { var cgf = new Configuration(); var data = cgf.Configure(HttpContext.Current.Server.MapPath(@"Models\NHibernate\Configuration\hibernate.cfg.xml")); cgf.AddDirectory(new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath(@"Models\NHibernate\Mappings"))); sessionFactory = data.BuildSessionFactory(); } return sessionFactory.OpenSession(); }