从域实体对象调用数据库
我正在尝试在一个项目上使用 PetaPoco,而不是我通常使用的 NHIbernate,并且我有一个关于集合以及从域模型中使用它们的问题。
假设我有一个带有名称和文本的 BlogPost,然后带有名称、作者、文本的评论
我想将 BlogPost 与评论相关联。我已经使用 Blogposts_Comments 表在 SQL 中完成了此操作。在 NHibernate 中,我只在 BlogPost 上有一个 Comments 集合并对其进行映射,然后将其检索或标记为 Lazy。
我想我可能会延迟加载这些评论,因此为此,我会在博客文章 GetComments() 方法中调用我的数据访问对象 GetCommentsForBlogPost(this) 。我的问题是,这被认为是好的做法吗?让您的域实体调用数据访问层?在我的 NHibernate 项目中,它们只处理自己,就像 NHibernate 代理/魔法处理其余的事情一样。
I'm having a go at using PetaPoco on a project rather than NHIbernate which I normally do, and I have a question about collections and using them from a domain model.
Lets say I have a BlogPost with Name and Text, and then Comments with Name, Author, Text
I want to associate BlogPost with Comments. I've done this in SQL with a Blogposts_Comments table. In NHibernate I'd just have a Comments collection on BlogPost and map that, which would then be retrieved or marked as Lazy.
I am thinking I might Lazy Load these Comments, so to do that, I'd call my data access object GetCommentsForBlogPost(this) in a Blog Post GetComments() method. My question is, is this considered good practice? Having your domain entities call the data access layer? in my NHibernate projects they just dealt with themselves as the NHibernate proxies/magic did the rest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,如果你这样做,你就不再拥有 POCO 对象..这是否是一件坏事真的取决于你。这实际上是保持域对象干净(可以说更易于维护)和让调用者的生活稍微轻松一点之间的权衡。
In my opinion, if you do this, you no longer have POCO objects.. whether or not that is a bad thing is really up to you. It's a tradeoff really between keeping your domain objects clean (arguably more maintainable), or making life only slightly easier for the caller.