Struggling to Comprehend nHibernate SchemaUpdate, even with Blog Posts

痴心易碎 提交于 2019-12-03 07:51:53

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:).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!