开发者

NHibernate repository SaveOrUpdate object graph

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜