I'm currently suffering my non-lazy loading app. Everything was beautiful locally, until I loaded in production-wide data. Now it's WAY too slow.
This is understandable, of course, because I have about 8 objects and only 2 are aggregate roots, so as soon as I load one of my objects, it traverses the object graph and loads all assicated collections.
I'm using Windows Forms (2.0) and my layers are separated as follows:
DomainModel: Persistent classes and mapping files. NO reference to DAL
DataAccessLayer: Repositories with NHibernate reference
UI: uses DAL to retrieve/save domain objects
Since my DomainModel doesn't have a reference to the DAL, I cannot implement lazy loading functionality, say through a base class and a level of indirection (ie: a property getter making a call to reconnecto to a session and hydrate the collection).
What patterns would you all suggest for working around this?
Does the UI have to explicitly tell the DAL what to load? Take the blog example, as it is so pervasive on this topic:
should I add these 2 methods? :
Code:
public Blog Load(int blogId)
{ Load(blogId, false); }
public Blog Load(int blogId, loadPosts)
{
//code to load blog/posts as necessary
}
? this seems like a heavy burden for the UI, but I'm considering it.
Another option I'm thinking is to remove the blog-> posts association and do everything by querying. Ie:
Code:
public IList<Post> GetPosts(Blog blog)
{
//... implement a query
}
....but I'm weary of design implications that this makes, as my entire DomainModel and DAL are already unit tested and ready... functionality-wise.
Thanks in advance for any advice.