Subsonic does not appear to be working for me


Over the past few days, I have been playing around with Rob Conery’s Subsonic project. Thus far, I have had a lot of good things to say about it. Today, I am not going to bash it, but I will state that I have hit the edge of the box.

Reiteration

First a bit of a reiteration of yesterday’s post, sans the integration tests. When you wish to work with the Repository for a single object, it is easy to load via the Repository. It goes like so:

provider = new SqlDataProvider();
provider.DefaultConnectionString =
"{connectionstring here}";
ISubSonicRepository
repository = new SubSonicRepository(provider);
Backend backend = repository.Get<Backend>(1);

When you want to load a collection of objects, you can use the Load() method on the collection:

BackendCollection coll = new BackendCollection();
coll.Load();

As I mentioned yesterday, I was not sure if this would cause an issue for me or not.

The Application and the Problem

First, I need to go through the application I am building. I won’t cover all of the gory details, but it works like this, in simple detail.

Simple Application

And Subsonic works rather well for this. To instantiate a single object, insert a new object, update an existing object or delete an object, I use the Repository. Rather nice. But, yesterday (as I mention here)  I found that collections work differently. The collection itself inherits from RepositoryList<ItemType,ListType>, which contains a Load() method. It is not using the Repository to load.

This may not sound like a big deal, and would not be in most applications, but the final status of the application is more like this:

RemoteApplication

This leads me to two kinds of changes. For The single object, I merely change the Repository used. But if I am using the Load method on the collection, I have to change the RepositoryList<ItemType, ListType> or I have to get even deeper.

I do see the Repository has a SaveAll method, which allows me to pass a RepositoryList, so there is nothing lost if I wish to go the full Repository route. But there is nothing on the Repository, as far as I can tell, to select the entire collection of objects, or even a filtered subset.

From what I can gather, the method of loading objects goes as follows (these are grossly oversimplified):

Objects

GettingSim

Collections

GettingSimCollection

Now, since both ultimately go to a database provider, I could theoretically use a web service provider. The issue here is the Load method would have to be completely rewire the Load() method, as it is coded to use a data reader:

using(IDataReader rdr = qry.ExecuteReader())

{

    LoadAndCloseReader(rdr);

    return this as ListType;

}

I will get through this, no doubt, but I am not fond of having two ways to accomplish one thing. I guess it is time to consider scrapping the defaults and move to my own methodology.

Next Steps

Back to being an architect. I need to figure out what the recipe is for the cookie I want to bake. After that, the rest is childsplay. I am looking at two options.

  1. Creating my own custom repositories for each RepositoryRecord<T> class to make sure all data access is through the Repository
  2. Altering the Load method to allow for a web service call
  3. Creating a different access method when using web services.

Of the two, the second would be best if I want to consider the web service another type of provider. The first would not require any changes to SubSonic, however. I will have to think of which is the better option, from a "purist" point of view.

As for option 3, I am not even considering it. I do not want to alter the methodology when going to SOA. It makes no sense to me to include two completely different methodologies for data access, just because I set a service boundary between components instead of a class boundary. Yes, they are different creatures, but it is only because we are examining transport methodology for data. When you go to an extremely high level, both are boundaries and should be treated as such. I should not have to write two completely different load methods simply because the project tightly couples itself to a single type of transport (albeit with multiple provider types).

Summary

I like SubSonic. I think it is a well thought out product and Rob has done a great job. I am a bit to SOA at present to utilize it across all layers and I am a bit too simple minded (Open-mouthed) to code two methodologies when one should suffice.

Peace and Grace,
Greg

Advertisements

One Response to Subsonic does not appear to be working for me

  1. Rob says:

    Hi Gregory – let’s see if I can offer some help…>>>I
    found that collections work differently. The collection itself inherits
    from RepositoryList<ItemType,ListType>, which contains a Load()
    method. It is not using the Repository to load.<<<First thing – collections don’t load themselves with the Repository pattern. They are there to hold dat and implement data rules, nothing else. You can switch out to our ActiveRecord pattern if you like this better.In this case, what you’d want to do is something like:MyCollection=new Select().From<MyTable>().ExecuteAsCollection<MyCollection>();… and you’re done.>>>The issue here is the Load method would have to be completely rewire the Load() method, as it is coded to use a data reader:<<<LoadAndCloseReader() uses a Reader, Load() does not. You can pass in a DataTable if you like – and we put it in there specifically for WebServices reasons. In fact, if you want, you can use our HttpHandler to pass XML data back and forth, and load stuff remotely (more on that if you like).Finally – your pictures aren’t showing up for me – Live is timing out so I can’t give you more advice. What I would say is that you might want to ask for help from our forums – or even send me an email – before you blog about what SubSonic can’t do (meant in a very nice way :).And one last thing:>>> I am not fond of having two ways to accomplish one thing<<<You’ll find that with SubSonic, you usually have five or so ways of doing the same thing :). This is to allow you flexibility. Send me an email at myname@gmail.com if you need more help.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: