views:

1347

answers:

4

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.

+1  A: 

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.

Scott Muc
I have actually tried that option, but RepositoryRecord is a SubSonic thing and therefore I would still be coupled to Subsonic.I also tried specifying my own base class as the 'tableBaseClass', but that didn't work as I got lots of build errors from the generated files.
NathanD
A: 

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.

John Sheehan
A: 

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.

NathanD
+1  A: 

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
Rick Ratayczak