當前位置:
首頁 >
FluentNhibernate 的数据库连接的配置
發布時間:2025/3/15
45
豆豆
生活随笔
收集整理的這篇文章主要介紹了
FluentNhibernate 的数据库连接的配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下載FluentNhibernate以后,添加全部的dll到項目中,其中已經包含了Nhibernate。
在配置文件中寫數據庫的連接字符串,我用的控制臺項目,用的app.config,名字叫db的數據庫連接字符串
private static ISessionFactory CreateSessionFactory()
??????? {
?????????? //FluentNHibernate.Cfg.Db.MsSqlConfiguration cfg =? FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008 ;//.Standard.ConnectionString(c => c.FromAppSetting("db"));
????????? return? Fluently.Configure()
???????????? .Database(
???????????? MsSqlConfiguration.MsSql2008.ConnectionString(
???????????? c => c.FromConnectionStringWithKey("db")))
???????????? .Mappings(x => x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
???????????? .BuildSessionFactory();
?????????? //return Fluently.Configure().BuildSessionFactory();
??????? }
在代碼中加入ExportTo(路徑),可以導出實體映射的hbm文件,可以方便比照對比。
?return? Fluently.Configure()
???????????? .Database(
???????????? MsSqlConfiguration.MsSql2008.ConnectionString(
???????????? c => c.FromConnectionStringWithKey("db")))
???????????? .Mappings(x => x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()).ExportTo(@"c:\\"))
???????????? .BuildSessionFactory();
只要寫出文件夾路徑之后,就會將所有的映射類全部生成對應hibernate中的hbm文件,很方便
在配置文件中寫數據庫的連接字符串,我用的控制臺項目,用的app.config,名字叫db的數據庫連接字符串
private static ISessionFactory CreateSessionFactory()
??????? {
?????????? //FluentNHibernate.Cfg.Db.MsSqlConfiguration cfg =? FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008 ;//.Standard.ConnectionString(c => c.FromAppSetting("db"));
????????? return? Fluently.Configure()
???????????? .Database(
???????????? MsSqlConfiguration.MsSql2008.ConnectionString(
???????????? c => c.FromConnectionStringWithKey("db")))
???????????? .Mappings(x => x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
???????????? .BuildSessionFactory();
?????????? //return Fluently.Configure().BuildSessionFactory();
??????? }
在代碼中加入ExportTo(路徑),可以導出實體映射的hbm文件,可以方便比照對比。
?return? Fluently.Configure()
???????????? .Database(
???????????? MsSqlConfiguration.MsSql2008.ConnectionString(
???????????? c => c.FromConnectionStringWithKey("db")))
???????????? .Mappings(x => x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()).ExportTo(@"c:\\"))
???????????? .BuildSessionFactory();
只要寫出文件夾路徑之后,就會將所有的映射類全部生成對應hibernate中的hbm文件,很方便
本文使用Blog_Backup未注冊版本導出,請到soft.pt42.com注冊。
轉載于:https://www.cnblogs.com/zjypp/archive/2011/04/16/2319304.html
總結
以上是生活随笔為你收集整理的FluentNhibernate 的数据库连接的配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python line.strip().
- 下一篇: mysql 8.0 重置数据库,Mysq