9

このチュートリアルに従おうとしていますが、マッピングを含む期待される hbm.xml ファイルを生成する代わりに、次のようなエンティティの単純な .cs クラスを生成します。

public class ProductMap : ClassMap<Product>

しかし、私はすでにそれらを自分でコードで定義しています。現時点では、標準の NHibernate で使用できる .hbm.xml を使用しています。

これは、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();
    }
4

1 に答える 1

9

ページの最後のセクションであるFluent_Configurationを参照してください。

このコードを示しています

.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");
})
于 2010-07-08T14:24:01.303 に答える