开发者

calling database from domain entity objects

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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜