Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net FluentNHibernate,如何验证/检查数据库?(SQL Server Express)_.net_Nhibernate_Fluent Nhibernate_Sql Server Express - Fatal编程技术网

.net FluentNHibernate,如何验证/检查数据库?(SQL Server Express)

.net FluentNHibernate,如何验证/检查数据库?(SQL Server Express),.net,nhibernate,fluent-nhibernate,sql-server-express,.net,Nhibernate,Fluent Nhibernate,Sql Server Express,使用SQL Server Express和FluentNHibernate: 我映射类,配置SessionFactory并执行SchemaExport;一切正常。但在程序启动时;您如何检查/验证这些表是否存在?Fluent中是否有一些功能可以帮助实现这一点 我想应该在不匹配上有一个弹出框,询问您是否要重建一个新的数据库 还有,还有什么需要验证的吗?(显然数据库存在除外)您可以使用此代码验证: SchemaValidator validator = new SchemaValidator(

使用SQL Server Express和FluentNHibernate:

我映射类,配置SessionFactory并执行SchemaExport;一切正常。但在程序启动时;您如何检查/验证这些表是否存在?Fluent中是否有一些功能可以帮助实现这一点

我想应该在不匹配上有一个弹出框,询问您是否要重建一个新的数据库


还有,还有什么需要验证的吗?(显然数据库存在除外)

您可以使用此代码验证:

    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");
        }
    }

OTOH,这是运行测试时要做的事情,而不是“在程序启动时”,除非数据库“神奇地”删除了它们的表。谢谢!不知道SchemaValidator:)…@Diego:是的,如果是“除非”,我们不想检查一下吗?有人可以轻松编辑除此特定软件之外的数据库。Idk虽然这很正常,但我没有数据库方面的经验。