9

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();
    }
Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61

1 Answers1

9

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");
})
Jason Watts
  • 3,800
  • 29
  • 33
  • Nope, didn't work for me. I only still get the .cs files. Not the hbm.xml ones. What exactly needs to go in the Add method? I left it out for now. – Kris van der Mast Jul 08 '10 at 14:33
  • If you look at the previous example.. it shows this in the add method AutoMap.AssemblyOf(type => type.Namspace.EndsWith("Entities"))); – Jason Watts Jul 08 '10 at 15:52
  • Thanks for the update, I'll take a look at it tomorrow morning (don't have the code here at home). – Kris van der Mast Jul 08 '10 at 17:56
  • For some reason I tried again with leaving the automappings part out of it, rebuilding the solution and trying again and they appeared. I marked your answer as such. Thanks for your time. – Kris van der Mast Jul 09 '10 at 13:20