2011-01-27 25 views
0

使用SQL Server Express和FluentNHibernate:FluentNHibernate,如何驗證/檢查數據庫? (SQL Server Express)

我映射類,配置SessionFactory並執行SchemaExport;一切正常。但是在程序啓動時,您如何檢查/驗證表格是否存在? Fluent有一些功能可以幫助嗎?

我想這將是適當的有一個彈出框不匹配,詢問你是否要重建一個新的數據庫?

此外,還有其他事情要驗證嗎? (除了明顯的是,數據庫存在)

回答

2

您可以使用此代碼來驗證:

SchemaValidator validator = new SchemaValidator(config); 
    try 
    { 
     validator.Validate(); 
    } 
    catch (HibernateException) 
    { 
     // not valid, try to update 
     try 
     { 
      SchemaUpdate update = new SchemaUpdate(config); 
      update.Execute(false, true); 
     } 
     catch (HibernateException e) 
     { 
      MessageBox.Show("invalid schema"); 
     } 
    } 
+0

OTOH,這是後話運行測試,而不是「在程序啓動」什麼時候做,除非數據庫「神奇」讓他們的桌子掉下來。 – 2011-01-27 12:57:03

相關問題