2010-07-08 12 views
9

sto cercando di seguire questa tutorial ma invece di generare i file hbm.xml attesi con i miei mappature in essa genera semplice classe cs per i miei soggetti, come ad esempio:Come generare file di hbm.xml da FluentNHibernate

public class ProductMap : ClassMap<Product> 

Ma ho già definito quelli stessi nel codice. Sto cercando il file .hbm.xml che posso utilizzare nello standard NHibernate in questo momento.

Ecco come ho creato la 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(); 
    } 

risposta

9

See: Fluent_Configuration, l'ultima sezione della pagina.

mostra questo codice

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

No, non ha funzionato per me. Ho ancora solo i file .cs. Non quelli di hbm.xml. Che cosa esattamente deve andare nel metodo Aggiungi? L'ho lasciato fuori per ora. – XIII

+0

Se si guarda l'esempio precedente, questo viene mostrato nel metodo di aggiunta AutoMap.AssemblyOf (type => type.Namspace.EndsWith ("Entities"))); –

+0

Vedere le modifiche al codice nella risposta. –

Problemi correlati