下载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注册。