NHibernate 存储库 SaveOrUpdate 对象图
我正在学习(流利)NHibernate,当前的挑战是了解如何编写存储库和DataService 类。如果我检索了对象图,并且已进行更改;既适用于根对象集合,也适用于子集合;有的被删除,有的被添加,有的被更新。我可以将整个对象放入 session.SaveOrUpdate 中吗?
这就是我目前所做的,它给了我许多不同的例外。我只需要知道我需要采取哪些步骤才能正确执行此操作?我是否需要单独深入并保存每个子集合?或者甚至每个子实体?
一些简单的例子会非常有帮助。
I'm learning (Fluent)NHibernate, and current challenge is to understand how to write Repositories and DataService classes. If I have retrieved an object graph, and changes has been made; Both to the root object collection, and child collections; some deleted, some added, some updated. Can I just throw this whole object into a session.SaveOrUpdate?
That's what I currently do, and it gives me a number of different exceptions. I just need to know what are the steps I need to take to do this properly? Do I need to drill down and save each child collection individually? Or even each child entity?
Would be really helpful with some simple examples on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google 上有很多很棒的示例,但入门NHForge.org 的区域是一个很好的起点。尝试搜索 NHibernate Cascade 或 FluentNHibernate Cascade。
不过,要直接回答您的问题,您需要确保您已通过 FluentNH 的约定。配置完成后,您应该能够 SaveOrUpdate() 顶级实体,并且删除/更新/创建将全部推送到数据库。
There are a ton of great examples to be Googled, but the Getting Started area at NHForge.org is a great place to start. Try searching for NHibernate Cascade or FluentNHibernate Cascade.
To directly answer your question, though, you need to ensure you've enabled an appropriate cascade type on properties in your mappings or (my preference) in your NHibernate configuration through FluentNH's conventions. Once that's configured, you should be able to SaveOrUpdate() a top level entity and the deletes/updates/creates will all be pushed to the database.