NHibernate复合应用程序-模块的启动记录

发布于 2024-11-26 15:16:36 字数 538 浏览 1 评论 0原文

我正在构建一个复合(Prism)WPF 应用程序。我设法构建了一些核心元素:例如从文件夹中发现模块。 我还使用 NHibernate (Fluent) 来保存数据。我能够分离模块,因此每个模块都有自己的模型和映射,当 Prism 添加模块时,它还会将映射添加到我的 nh 配置中。

我想做的是在启用从未启动过的模块时插入一些启动记录。 例如:

当我第一次启动我的应用程序时,它检测到没有数据库并创建一个,只有一个配置表。该表包含有关启用哪个模块的信息。然后管理员可以通过 UI 配置应用程序应启用哪些模块。下次应用程序启动时,它会从新启用的模块中检测新选项卡,并使用 NH UpdateSchema 创建其表。我想做的是通过此表创建插入一些启动记录。 我认为这应该由 NH events 来完成(NH events 文档)。像“PostTableCreateEvent”这样的东西会很好,但我找不到这样的东西。

你们有人做过这样的事吗?

I am building a composite (Prism) WPF application. I hava managed to build some core elemets: for example module discovery from folder.
I am also using NHibernate (Fluent) to persist data. I was able to separate modules so every has it's own model and mapping, and when Prism adds module it also adds mappings to my nh configuration.

What I would like to do is to insert some startup records when a module, that has never been started, is enabled.
For example:

When I first start my app, it detects that there is no db and creates one, only with one configuration table. This table contains info about which module is enabled. Then admin can configure app through UI which modules should be enabled. Next time the app starts it detects new tabs from newly enabled modules and creates their tables using NH UpdateSchema. What I would like to do is to also insert some startup records with this table create.
I think this should be done by NH events (NH documentation on events). Something like 'PostTableCreateEvent' would be nice but I can't find anything like this.

Did any of you do something like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗梦空间 2024-12-03 15:16:36

事件在会话中触发,但 Schemaexport 不使用 sessionfactories 或会话,因此您无法挂在其中。为此,您需要的是 INSERT ... 中xml 映射或纯 sql,因为 FNH 不支持 afaik。

选项 1:在创建 NH-Configuration 时添加 Fluent 和 hbm.xml 映射,并使用 嵌入映射

选项 2:允许模块在创建表后采取其他步骤 (sql) (对于我的一个项目,我将 Schemaexport 包装在我自己的类/方法中,它还创建数据库本身,该数据库本身不由 schemaexport 处理,并插入自定义数据,例如 schemaversion 和配置)

Events are triggered in sessions but Schemaexport doest take sessionfactories or sessions, so you cant hook in there. For this what you want there is <database-object><create>INSERT ...</create><drop></drop></database-object> in xml mappings or plain sql since FNH doesnt support <database-object> afaik.

Option 1: add fluent and hbm.xml mappings on creation of NH-Configuration and embed Mappings with <database-object>

Option 2: allow Modules to take additional steps (sql) after Creation of tables ( for one of my projects i wrapped Schemaexport in my own class/Method which also creates the database itself which isnt handled by schemaexport and inserts custom data like schemaversion and configs)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文