views:

55

answers:

1

This question was asked before but the answers all show how to export the hbm files from fluentnhibernate. We are using S#arpArchitecture which wraps fluent. I am able to export the schema but what I really want is the xml files to troubleshoot errors. I've done this using FNH before but adding S#arp to the mix has complicated things where I cannot figure it out.

I've found this question asked on several forums, but I can't find one that shows how to get the mapping files.

+1  A: 

Here is how I do it in one of my projects:

[TestMethod]
    public void CreateSchema()
    {
        var mappingOutput = ConfigurationManager.AppSettings["xmlMappingOutputDirectory"];
        var sqlOutput = ConfigurationManager.AppSettings["sqlOutputDirectory"];

        Configuration cfg = new Configuration().Configure();
        var persistenceModel = new PersistenceModel();
        persistenceModel.AddMappingsFromAssembly(Assembly.Load("ProjectName.Data"));
        persistenceModel.Configure(cfg);
        persistenceModel.WriteMappingsTo(mappingOutput);
        new SchemaExport(cfg).SetOutputFile(sqlOutput).Create(true, false);
    }

You will need to set the two keys in the your app config or provide values directly for them.

Alec Whittington
Thanks, What namespace do I need for Configuration cfg = new Configuration().Configure();
Maggie
using Configuration = NHibernate.Cfg.Configuration;
Alec Whittington
Thanks, I got it to work!
Maggie