How to generate hbm.xml file from FluentNHibernate

 ̄綄美尐妖づ 提交于 2019-12-10 12:43:54

问题


I'm trying to follow this tutorial but instead of generating the expected hbm.xml files with my mappings in it generates simple .cs class for my entities like for example:

public class ProductMap : ClassMap<Product>

But I already defined those myself in code. I'm after the .hbm.xml which I can use in standard NHibernate at this time.

This is how I set up the 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();
    }

回答1:


See : Fluent_Configuration, the last section of the page.

It shows this code

.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");
})


来源:https://stackoverflow.com/questions/3204548/how-to-generate-hbm-xml-file-from-fluentnhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!