2010-11-20 16 views
0

Veritabanımda bir tablo oluşturmak için NHibernate/FluentNHibernate kullanıcısı çalışıyorum. Çoğu zaman bunu anladım gibi görünüyor ama testi çalıştırdığımda tablo oluşturulmuyor. Yapılandırma nesnesinde, ClassMappings'in büyük bir yağ sıfırı olduğunu görüyorum, hatta bunları bir montajdan yapılandırmak için FluentNHibernate kullanıcısına sahibim. Biraz anlıyorum ama bir yerdeki bağlantıyı kaçırıyorum ... İşte kod parçacıkları, belki birileri ne olduğunu görebiliyor mu?NHibernate ClassMappings = 0

İşte dataconfig sınıfım.

public static FluentConfiguration GetFluentConfiguration() 
    { 
     string hibernateCfgFile = @"C:\Users\kenn\Documents\Visual Studio 2008\Projects\NHibernateTestTwo\Infrastructure\hibernate.cfg.xml"; 
     return Fluently.Configure(new Configuration().Configure(@hibernateCfgFile)) 
      .Mappings(cfg => cfg.FluentMappings.AddFromAssembly(typeof(AddressMap).Assembly)); 
    } 

İşte test dersi. İşte

[Test, Explicit] 
    public void SetupDatabase() 
    { 
     FluentConfiguration conf = DataConfig.GetFluentConfiguration(); 
     conf.ExposeConfiguration(BuildSchema).BuildSessionFactory(); 
    } 

    private static void BuildSchema(Configuration conf) 
    { 
     new SchemaExport(conf).SetOutputFile("drop.sql").Drop(false, true); 
     new SchemaExport(conf).SetOutputFile("create.sql").Create(false, true); 
    } 

Açıkça ... eşleştirmeleri

public AddressMap() 
    { 

     Table("Address"); 
     DynamicUpdate(); 
     Id(a => a.Id).GeneratedBy.GuidComb(); 
     Map(a => a.AddressOne).Not.Nullable().Length(100); 
     Map(a => a.AddressTwo).Length(100); 
     Map(a => a.City).Not.Nullable().Length(100); 
     Map(a => a.state).Not.Nullable().Length(100); 
     Map(a => a.zip).Not.Nullable().Length(50); 
     Map(a => a.Primary).Not.Nullable(); 

    } 

hibernate.cfg.xml dosyası

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
<session-factory> 
    <property name="connection.driver_class"> 
     NHibernate.Driver.SqlClientDriver 
    </property> 
    <property name="connection.connection_string"> 
     Data Source=MYPC;Initial Catalog=NHibernateSample;Integrated Security=True; 
    </property> 
    <property name="show_sql">true</property> 
    <property name="dialect"> 
     NHibernate.Dialect.MsSql2005Dialect 
    </property> 
    <property name="adonet.batch_size">100</property> 
    <!--<property name="proxyfactory.factory_class"> 
     NHibernate.ByteCode.LinFu.ProxyFactoryFactory, 
     NHibernate.ByteCode.LinFu 
    </property>--> 
    <property name="proxyfactory.factory_class"> 
     NHibernate.ByteCode.Castle.ProxyFactoryFactory, 
     NHibernate.ByteCode.Castle 
    </property> 
</session-factory> 

Ben orada ne eksik sadece emin değilim olduğunu Veritabanının adını değiştirmeyen bir şeye değiştirirsem DB'ye konuşuyor çünkü ben bir istisna atarım. Bu konuya devam ettim ve henüz çözmedim, bu yüzden henüz herhangi bir yardım büyük ölçüde takdir edilecektir.

Teşekkürler!

+0

Oh turd ... AddressMap sınıfını herkese açık yapmayı unuttum. Eh, eğer herkes bu konuda umarsa bu yardımcı olacaktır. :) – Kenn

cevap

1

Yorumumu görün ... Harita sınıflarınızı herkese açık yapmayı unutmayın veya FluentNHibernate onları görmez.