Question

I want to use SubSonic (2.2) in an application I'm building because I like its simplicity and it handles any type of query I can foresee needing. At the same time, I want to keep the upper layers of my application de-coupled from the Subsonic Types. I want to return just Plain Old C# Objects and also pass in POCOs to be saved.

But here's the catch: I want my POCOs to have Lazy loaded properties for Child collections and parent objects based upon the FK relationships. I figure I need to somehow put a Subsonic SqlQuery object in a private member on my POCO and use that internally in the getter for a lazy loaded property.

Any ideas about how to implement this specifically with SubSonic? Anyone done this before?

I do realize that the next major release of SubSonic will do this out-of-box, but that looks to be atleast a few months away.

Was it helpful?

Solution 4

Couldn't ever figure out a good way to do this. Subsonic 3 is looking very nice and would solve the problem, but in the mean time we just went with NHibernate.

OTHER TIPS

I use the RepositoryRecord in SubSonic which is "mostly" poco. Then I make partials for those classes that load the other class when a property is selected.

Partial Public Class Book

Private _Author as Database.Author 
Property Author() as Database.Author
  Get
     If _Author is nothing then
       ' Load the author class here.
     End if
     return _Author
  End get
  Set
     ....
  End Set
End Property
End Class

You can use the attribute:

tableBaseClass="RepositoryRecord"

I'm afraid I don't know how this handles the lazy loading though. You can see Rob Conery's post about it for more details.

What you want is not in version 2.x. You might be able to get most of the way there by editing the templates (I have examples of lazy-loaded properties on my blog). Another option is to build up your pocos then build classes to map from the SubSonic generated classes and queries to your model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top