我正在尝试遵循这个tutorial http://www.dotnetguy.co.uk/post/2009/10/19/using-fluent-Nhibernate-to-Export-Create-hbm-files-(Nhibernate-mapping-files).aspx但不是使用我的映射生成预期的 hbm.xml 文件,而是为我的实体生成简单的 .cs 类,例如:
public class ProductMap : ClassMap<Product>
但我已经在代码中自己定义了这些。我正在寻找此时可以在标准 NHibernate 中使用的 .hbm.xml 。
这就是我设置 SessionFactory 的方式:
private static ISessionFactory CreateSessionFactory()
{
String schemaExportPath = Path.Combine(System.Environment.CurrentDirectory, "Mappings");
if (!Directory.Exists(schemaExportPath))
Directory.CreateDirectory(schemaExportPath);
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c =>c.FromConnectionStringWithKey("connectionString"))
.Cache(c => c.UseQueryCache()
.ProviderClass<HashtableCacheProvider>()).ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>().ExportTo(schemaExportPath))
.ExposeConfiguration(c => new SchemaExport(c).SetOutputFile(@"c:\temp\test.sql").Create(false, true))
.BuildSessionFactory();
}
See : Fluent_配置 http://wiki.fluentnhibernate.org/Fluent_configuration#Exporting_mappings,页面的最后一部分。
它显示了这段代码
.Mappings(m =>
{
m.FluentMappings
.AddFromAssemblyOf<YourEntity>()
.ExportTo(@"C:\your\export\path");
m.AutoMappings
.Add(AutoMap.AssemblyOf<YourEntity>(type => type.Namspace.EndsWith("Entities")));)
.ExportTo(@"C:\your\export\path");
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)