2010-07-08 21 views
9

Tôi đang cố gắng theo dõi tutorial nhưng thay vì tạo các tệp hbm.xml dự kiến ​​bằng ánh xạ của tôi, nó tạo ra lớp .cs đơn giản cho các thực thể của tôi như ví dụ:Cách tạo tệp hbm.xml từ FluentNHibernate

public class ProductMap : ClassMap<Product> 

Nhưng tôi đã tự xác định những mã đó. Tôi là sau khi .hbm.xml mà tôi có thể sử dụng trong NHibernate tiêu chuẩn tại thời điểm này.

Đây là cách để tôi thiết lập 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(); 
    } 

Trả lời

9

Xem: Fluent_Configuration, phần cuối của trang.

Nó cho thấy mã này

.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

Nope, không làm việc cho tôi. Tôi chỉ nhận được tệp .cs. Không phải tệp hbm.xml. Chính xác những gì cần phải đi trong phương pháp Thêm? Tôi để nó ra ngay bây giờ. – XIII

+0

Nếu bạn nhìn vào ví dụ trước .. nó cho thấy điều này trong phương pháp thêm AutoMap.AssemblyOf (type => type.Namspace.EndsWith ("Entities"))); –

+0

Xem các thay đổi đối với mã trong câu trả lời. –

Các vấn đề liên quan