FluentNHibernate, How to validate/check database? (SQL Server Express)
With SQL Server Express and FluentNHibernate:
I map classes, configure SessionFactory and execute SchemaExport; Everything works. But on program-startup; How do you check/verify th开发者_开发问答at the tables exist? Are there some features in Fluent to assist with this?
I imagine it would be proper to have a pop-up box on mismatch, asking if you want to rebuild a fresh database?
Also, are there any other things to validate? (Except obviously that the database exists)
You can use this code to validate:
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");
}
}
精彩评论