Generate XML mappings from fluent Nhibernate

How do I generate xml mappings files as part of my tests in MappingIntegrationTests

I need to manually check if the fluent mappings correlate to the mappings in the leagcy project.

Can Fluent NHibernate support all mappings from NHibernate

I want to use Fluent NHibernate with NHibernate. But I want to find out whether Fluent NHibernate support all mappings from NHbernate. Or is it better to stick with NHibernate?

NHibernate generate mappings from classes?

Is there a way to generate mappings for NHibernate from POCO? This reply to my question makes NHibernate look very interesting. However i have a lot of classes that look like this public class registe

Tool to generate Fluent NHibernate mappings

I am trying to integrate NHibernate into an existing application with several hundred tables. Due to the fact that there apparently wasn’t a strict adherence to conventions, I am unable to use Automap

Unit tests for Fluent Nhibernate mappings

I’m trying to get a feel for how the rest of the community tests their Fluent Nhibernate mappings. So let’s say I have the following mappings: public UserHeaderMap() { Table(USER_HEADER); Id(x =&gt

Fluent NHibernate mappings for localization

I am trying to build a Database from NHibernate mappings and have run into a problem. I have many classes with localized string values: public class MyClass1 { public virtual int Id { get; set; } publ

ArgumentOutOfRangeException Fluent NHibernate Export Mappings

First off, I am extremely new with using NHibernate and Fluent NHibernate so it’s very likely that I’m making a simple mistake. I jumped right into NHibernate over the last few days using Fluent NHibe

Does FluentNH’s PersistenceSpecification allow XML mappings to be tested?

Is it possible to use Fluent NHibernate’s PersistenceSpecification to test NHibernate mappings done via XML?

NHibernate: Generate mappings for stored procedures

I need to call some stored procedures via NHibernate (not necessarily for CRUD-operations). Is there a freeware/open source tool which can generate mappings (a hbm.xml) for stored procedures and table

Legacy Database, Fluent NHibernate, and Testing my mappings

As the post title implies, I have a legacy database (not sure if that matters), I’m using Fluent NHibernate and I’m attempting to test my mappings using the Fluent NHibernate PersistenceSpecification

Fluent NHibernate XML Field

Is there a way to map an XML field using Fluent Nhibernate. If you have an XML field in MSSQL database, how would you Map using Fluent NHibnernate? Example Table(Address); LazyLoad(); Id(x =>

Answers

You generate XML mappings by calling the ExportTo() method.

For example:

ISessionFactory sessionFactory = FluentNHibernate.Cfg.Fluently.Configure()
  .Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008
    .ConnectionString(connectionString)
  )
  .Mappings(m => m.FluentMappings.AddFromAssembly(assembly)
    .ExportTo(@"C:/your/export/path")
  )
  .BuildSessionFactory();

See here for documentation:

http://wiki.fluentnhibernate.org/Fluent_configuration

You can do something like:

 config.Mappings(m => 
    {
        m.FluentMappings.ExportTo("...file path here...");
        m.HbmMappings.ExportTo("...file path here...");
        m.AutoMappings.ExportTo("...file path here...");
    {
);

I don’t like it myself. If I find some better way (if such exists at all) I’ll update the answer.

See
http://blog.jagregory.com/2009/02/03/fluent-nhibernate-configuring-your-application/

I use (almost) this extension method to get the xbm in memory so I can view it in my test project:

   public static IDictionary<string, string> LoadHBM(this FluentConfiguration cfg)
    {
        var result = new Dictionary<string, string>();
        var mem = new MemoryStream();
        var writer = new StreamWriter(mem);
        var reader = new StreamReader(mem);

        cfg.Mappings(x =>
        {
            x.FluentMappings.ExportTo(writer);
            x.AutoMappings.ExportTo(writer);
        });

        cfg.BuildConfiguration();
        writer.Flush();
        mem.Seek(0, 0);
        var hbm = reader.ReadToEnd();

        var objects = XElement.Parse("<junk>" + hbm + "</junk>").Elements();
        objects.ToList().ForEach(x => result.Add(x.Elements().First().Attribute("name").Value, x.ToString()));
        return result;
    }

Edit: Updated for FNH 1.2.