Respuesta

18

Usted puede hacer algo como:

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

no me gusta a mí mismo. Si encuentro alguna forma mejor (si existe) actualizaré la respuesta.

Ver
http://blog.jagregory.com/2009/02/03/fluent-nhibernate-configuring-your-application/
O si está rota, ver esto en vez
https://github.com/jagregory/fluent-nhibernate/wiki/Database-configuration

+0

Al menos con una versión actual de FluentNH (por ejemplo, 1.3), 'm.HbmMappings.ExportTo()' no existe, lo que tiene cierto sentido ya que las asignaciones .hbm ya son archivos. – Oliver

+1

Esto me ayudó mucho. +1 –

+0

El enlace está roto –

8

Genera asignaciones de XML llamando al método ExportTo().

Por ejemplo:

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(); 

ver aquí para documentación:

http://wiki.fluentnhibernate.org/Fluent_configuration

+0

El enlace está roto –

3

utilizo (casi) este método de extensión para obtener el xbm en la memoria para que pueda visualizarla en mi proyecto de prueba:

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; 
    } 

Editar: Actualizado para FNH 1.2.

Cuestiones relacionadas