Domanda

Sto cercando di seguire questo tutorial ma invece di generare i file hbm.xml previsti con i miei mapping in esso genera una classe .cs semplice per le mie entità come ad esempio: .

public class ProductMap : ClassMap<Product>
.

Ma ho già definito quelli me stesso nel codice.Sono dopo il .hbm.xml che posso usare in NHibernate standard in questo momento.

Ecco come ho impostato 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();
    }
.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top