使用SQL Server Express和FluentNHibernate:
我映射类、配置SessionFactory并执行SchemaExport;一切都正常。但是在程序启动时,如何检查/验证表是否存在?Fluent中有没有一些特性可以帮助你做到这一点呢?
我想在不匹配时弹出一个对话框,询问你是否想重建一个新的数据库是合适的。
另外,还有其他东西需要验证吗?(除了明显存在数据库之外)
发布于 2011-01-27 20:40:14
您可以使用此代码来验证:
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");
}
}https://stackoverflow.com/questions/4816115
复制相似问题