How to update database table schemas with NHibernate schema generation?

后端 未结 1 1935
半阙折子戏
半阙折子戏 2020-12-02 06:52

I\'m trying to figure out how to use NHibernate configuration with mapping to update table schemas, rather than dropping and recreating them.

Currently I\'m using th

相关标签:
1条回答
  • 2020-12-02 07:27

    The SchemaUpdate object provides database schema updating, by apparently generating and executing a series of SQL UPDATE statements (as well as constraint statements) when it's void Execute(bool script, bool doUpdate) function is called. The SchemaUpdate class is in the NHibernate.Tool.hbm2ddl namespace, which can be found in the Nhibernate.dll file.

    SchemaUpdate is mentioned in chapter 15 of the nhibernate 1.0.2 toolset guide, here (section 15.1.5).

    "The NHibernate FAQ" had (link now expired) a more complete example of how to use SchemaUpdate:

    [Test]
    public void Update_an_existing_database_schema()
    {
        _cfg = new Configuration();
        _cfg.Configure();
        _cfg.AddAssembly(Assembly.LoadFrom("DataLayer.dll"));
        var update = new SchemaUpdate(_cfg);
        update.Execute(true, false);
    }
    
    0 讨论(0)
提交回复
热议问题