Repository pattern with lazying loading using POCO

Posted by Simon G on Stack Overflow See other posts from Stack Overflow or by Simon G
Published on 2010-04-08T10:08:04Z Indexed on 2010/04/08 10:13 UTC
Read the original article Hit count: 634

Hi,

I'm in the process of starting a new project and creating the business objects and data access etc. I'm just using plain old clr objects rather than any orms. I've created two class libraries: 1) Business Objects - holds all my business objects, all this objects are light weight with only properties and business rules. 2) Repository - this is for all my data access.

The majority of my objects will have child list in and my question is what is the best way to lazy load these values as I don't want to bring back unnecessary information if I dont need to.

I've thought about when using the "get" on the child property to check if its "null" and if it is call my repository to get the child information. This has two problems from what I can see: 1) The object "knows" how to get itself I would rather no data access logic be held in the object. 2) This required both classes to reference each other which in visual studio throws a circular dependency error.

Does anyone have any suggestions on how to overcome this issue or any recommendations on my projects layout and where it can be improved?

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about design-patterns