开发者

FluentNHibernate, How to validate/check database? (SQL Server Express)

开发者 https://www.devze.com 2023-02-06 20:47 出处:网络
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

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号