chris carter's web log

Home |  Contact |  Admin
 

Brute Force? I guess I'll just use SubSonic then...

Posted on September 18, 2007

I'm working on a project now that is a rush job.  Gee, what's new.  Well, there's no project manager(read:anybody who can(should) successfully get us from point A to point B even if that means changing what point B means), and there's not much technical direction.  Luckily, there are about 7 developers, and no technical lead, so basically it's a free for all.  OK, fine. 

"The" Business Object

One developer added "The" business object, a single class containing one class per table in the database schema which is under constant change.   That's fine, unfortunately the "tool" generated 11,000 lines of code.  Again, no biggie.  The problem is that the code doesn't even do one thing, nothin.  They are classes with no more that one property for each field in the table that a class "represents".  That's it.  Funnily enough that didn't immediately pull a *WTF* to me, it was more of a "Huh?". There were no other classes that fill those classes with data or anything, just a bunch of models and that's all folks.

I was thinking that I would try to make some kind of use out of the code by making them all inherit from ActiveRecordBase, put on the right attributes and voila! Useful code.  However the schema is changing rapidly and there's no access to the magic tool that generated the classes in the first place.  So not wanting to be the maintainer of that code(there are almost 100 tables), I went in search of other solutions, determined NOT to write straight sql.

Just Use Brute Force...

I asked another developer working on the project what they were using for interacting with the database.  The response I got obviously spawned this post: "We don't have enough time, I'm just using brute force and writing straight sql and ado.net".

 The Brute Force comment pulled a *WTF* from me.  That's reminiscent of the dot bomb days when you'd write your straight sql by hand for 25 hours a day and spent(read: wasted) most of your time maintaining that stuff and fighting every database change for fear of having to dive into your beautifully hand crafted sql. 

No Thanks...

Enter SubSonic

 I'm a fan of the BuildProvider concept and building the data layer on the fly I learned about when SubSonic was just getting started.  I've rolled a similar approach as a proof of concept using castle's ActiveRecord for the data access.  Anywho, that sure seemed like the approach I wanted.  This was the first post I read by Rob on SubSonic and it's gotten VERY good since then.  Today I watched this screen cast and was sold on picking up the latest version and integrating in our solution.  I was instantly talking to the database without typing one line of sql.  If that's not "brute force" I don't know what is. 

"The Schema Changed and Now I Have to go Fix My Sql"

 Huh.  I reran SubCommander and in approximately 15 seconds, my data layer was regen'd and all changes were now in my code.  Man, I should've used brute force.  Maybe next time...

kick it on DotNetKicks.com

Comments

Brock

Very Cool. I'm pretty sure you've been in contact with the LLBL. How does it compare?

Chris

Well it was a lot cheaper(free), less functionality, but that's compared to LLBL which has more functionality than can be imagined.

It gen's the files to where ever you want(i.e. a subdirectory in your current project), and I'm not sure if LLBL gives you the option of not having a separate project for the data.

Following the tutorial on setting up SubSonic as an external tool was a huge help. No need to fire up a second app to regen the classes.

One hiccup this morning was when a table was deleted(by design), I regen'd the dal but that extra class for the deleted table hung around so I got error, I removed the now deleted class/table from the project and life was good again.

I still don't like how it returns an IDataReader when you call something like a FetchAll(), because you then have to pass that to to a collection instance and then close the reader, I'd rather not know about the IDataReader, call FetchAll and just get back the collection, but that's probably just my personal taste. It's easy enough to load collections, so I'm not bitching too much 'bout that.

Will Asrari

Brute Force. Reminds me of a place I used to work where the response to a question of data access practices would always result in "Just create a cursor."

I haven't used SubSonic yet but have been using 2 (one for work, one for play) OR/M mappers. When my database schema changes I just regenerate. It's definitely a lot nicer than some of my old colleagues performing Find-Replace ALL and crossing their fingers nothing else broke. :-)

In the last year I've become a big fan of OR/M and Reflection.

John Baughman

Hey, I've used an older version of SubSonic in an app I worked on earlier this year. It saved a TON of work. I actually discovered it in a round about way by using the PayPal enabled eCommerce starter kit, which is now called dashCommerce (http://www.dashcommerce.org/).

Considered using it at work, but (unfortunately) went with CSLA. (Big "UGH") That is definitely half brute force, half "WTF". Now we are trying to pull it out. Not pretty.

Chris

Hey, I know you!

eh eh, yes, since my last non gov't related project that used CSLA, I vowed never to ruin my code with such frameworks. I make mistakes, and I 've written my fair share of shitty code(and continue to do so as sparinly as possible), but nothing is worse than getting stuck with CSLA.

SubSonic rocks, they just need better support for POST(Plain Old Sql Transactions). What this means is that object is allowed to to complete it's entire "roundtrip" before the next action takes place in the transaction. Little confusing, but it's required a custom code change on our part. I supplied a patch but I'm new to the process so I'm thinking the SubSonic folks caught my patch, had a good laugh, and put me on the backburner. Lack of support for real object transactions should be considered a bug and/or just the way I view what a transaction really is.

Post a Comment

(required)
(required)
(no HTML!)