2011-01-19 57 views
5

Đang cố gắng để chơi xung quanh với IInterceptor trong NHibernate 2.1.2.4000 tôi đã có chút sau của mã kiểm tra:Tại sao hbm2ddl.SchemaExport không chạy ở đây?

public class TestingNHibernateInterceptors 
{ 
    [Fact] 
    public void can_intercept_delete_for_audit_log() 
    { 
     FullyConfigureDb(); 
     Session(s => s.Linq<Person>().Any().ShouldBe(false)); 
    } 
    ISessionFactory _sessions; 
    void Session(Action<ISession> @do) 
    { 
     using (var s = _sessions.OpenSession()) 
     { 
      @do(s); 
      s.Flush(); 
     } 
    } 
    void FullyConfigureDb() 
    { 
     var cfg = CreateConfig(); 
     _sessions = cfg.BuildSessionFactory(); 
     BuildSchema(cfg); 
    } 
    Configuration CreateConfig() 
    { 
     return Fluently.Configure() 
      .Database(new SQLiteConfiguration().InMemory()) 
      .Mappings(x => x.FluentMappings.Add<PersonMap>()) 
      .BuildConfiguration() 
      .SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle") 
      .SetProperty("show_sql", "true"); 
    } 
    void BuildSchema(Configuration config) 
    { 
     var se = new NHibernate.Tool.hbm2ddl.SchemaExport(config); 
     se.Execute(false, true, false, _sessions.OpenSession().Connection, null); 
    } 
    public class Person 
    { 
     public virtual Guid Id { get; private set; } 
     public virtual string Name { get; set; } 
    } 
    public class PersonMap : ClassMap<Person> 
    { 
     public PersonMap() 
     { 
      Id(x => x.Id); 
      Map(x => x.Name); 
     } 
    } 
    public class AuditInterceptor : EmptyInterceptor, IInterceptor 
    { 
     public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types) 
     { 
      base.OnDelete(entity, id, state, propertyNames, types); 
     } 
    } 
} 

Tuy nhiên. Tôi tiếp tục nhận được thông báo:

thất bại: NHibernate.ADOException: không thể thực hiện truy vấn [CHỌN count (*) là y0_ TỪ "Person" this_] [SQL: SELECT count (*) là y0_ TỪ "Person" this_] ---- System.Data.SQLite.SQLiteException: lỗi SQLite

Schema xuất khẩu dường như được làm việc - tại sao bàn không được tạo ra?

Tôi đoán điều này có liên quan đến việc sử dụng bộ nhớ trong sqllite nhưng không chắc chắn vấn đề là gì. Bất kỳ ý tưởng?

Trả lời

3

Been ở đó, làm điều đó, bị thương quá ;-)

Khi phiên được phát hành, cơ sở dữ liệu về cơ bản là giảm. Khi bạn sử dụng các phiên khác nhau khi xây dựng lược đồ của mình và khi chạy thử nghiệm, lược đồ không tồn tại nữa khi thử nghiệm đang được chạy.

Xem điều này post từ Justin để được giải thích rất rõ ràng.

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