Struggling to Comprehend nHibernate SchemaUpdate, even with Blog Posts

前端 未结 1 1621
无人共我
无人共我 2021-02-09 20:06

I\'ve seen the various blog posts concerning nHibernate\'s SchemaUpdate, and even Ayende\'s very good example, and downloaded the samples, but for some

1条回答
  •  一向
    一向 (楼主)
    2021-02-09 20:50

    Your example works well for me (NH3.1, FNH 2.1). SchemaUpdater checks current database schema and creates correct alter scripts. All generated script fragments are exposed to UpdateSchema. No problem here. The only one detail which I was confused by is file mode access:

    1. First Map run: Whole database schema script is stored in update.sql file. Note that there the script is not executed yet, because doUpdate parameter is false: SchemaUpdater.Execute(updateExport, false);
    2. Execute update.sql file manually - database schema is created.
    3. Change in FNH mapping (e.g. a property is added).
    4. Second Map run: Corretct alter table script is appended to update.sql file.

    Maybe it would be better to remove the output file before schema update.

    The generated script can be executed automatically (doUpdate parameter is true):

    SchemaUpdater.Execute(updateExport, true);
    

    I don't know if it is your case but I'm happy now - your code snippet solved some of my problems. Thanks for inspiration:).

    0 讨论(0)
提交回复
热议问题