Jason Salas' WebLog

On-air and online: making people laugh, making people think, pissing people off

Sponsors

ASP.NET sites that kick ass

Pals with blogs

Podcasts I listen to

Suggestion for ADO.NET 2.0: better SqlCommandBuilder support

I've long been a fan of the concept of the .NET Framework's SqlCommandBuilder class in theory, if not fully in practice.  I appreciate the foundation upon which it was designed - to automatically generate potentially complex SQL code for CRUD operations, and when used with the SqlDataAdapter.Update() method, making for very simple modification of database-born content  - being well-conceived, although (not unexpectedly) many in the community aren't as liberal in their support of it. 

A project I worked on today had several database tables use several JOINs, which instantly led me to discount the opportunity to use a SqlCommandBuilder, opting for manually building a dynamic SQL string and use SqlParameters.  I tried to trick the Framework into supporting an UPDATE operation by creating a View of data originating in 5 different tables on the DB.  No dice - I still got the "dynamic SQL generated cannot come from multiple base tables" error.  Darn.

I honestly think the concept is cool, but in my own development is rarely implemented, as the chance by which I actually query a single table with "SELECT * FROM Table" is rare-to-nil.

That having been said, I think a couple of changes would be great to make for the next version of ADO.NET (I admittedly haven't kept up as well as I should with such features):
  • More SqlCommandBuilder constructor overloads - supporting selectable parameters so that the SQL generated by the object itself can contain a selectable number of fields, rather than having the long, drawnout UPDATE statements that test the nullability state of each and every field in a recordset, improving performance.  Perhaps implementing a signature like SqlCommandBuilder(SqlParameter[] sql).
  • Support JOINed tablular data - I know this is a big one, but I think it would be cool to support even simple multi-table data.   As evident above, quite even a simple JOIN kills any use for a SqlCommandBuilder for me.  And I know I'm not alone.
  • Be able to support JOINed tabular data derived from a database-side View - if the Framework is smart enough to recognize that a View utilizes 2 or more base tables, then why not be able to bake-in a feature that could provide UPDATE capability to those tables.  At least for the more simple of JOIN operations.
In all, I'd like to see the SqlCommandBuilder be a much more reliable part of .NET than just the obligatory lesson learned in what can be done - and then back it up.

Comments

Wallym said:

Hey Jason. How is Guam? Long time since I have heard from you or sent anything to you. I hope all is going well on the other side of the world from me. :-)

Yeah, I'm not a big fan of the command builder myself. I've looked at the commands that it sends to a database, and all I can really say is yuck. I haven't looked at in Whidbey, but I should.

Wally
# February 15, 2005 7:03 AM

Jason Salas said:

Hey Wally!

Yeah....it's been awhile. Wow...a data access guru like you not getting into the next ADO.NET is major! :)
# February 15, 2005 7:05 AM

Jason Salas said:

Hopefully, someone from the MS ADO.NET team will see this and either say my rquest wasn't unique and that the changes are in the works, say it's not possible, or say they'll look at it. Cool by me either way.
# February 15, 2005 7:07 AM

Charles Chen said:

There are tons of better open source tools out there that do exactly this and can support much more complex queries.

NHibernate comes to mind as one of the better ones that I've seen. It does involve writing some XML, but the initial preview of ObjectSpaces works on a similar concept (object XML, mapping XML, and table XML). The nice thing about NHibernate is that it's based off of the relatively mature Hibernate framework for Java. There's plenty of documentation (albeit for Hibernate, but the two are mostly compatible), there's good tool support for auto generating schemas and classes from mapping XML files, and it's highly flexible.

Two good intro resources:
http://www.theserverside.net/articles/showarticle.tss?id=NHibernate
http://www.theserverside.net/articles/showarticle.tss?id=NHibernateP2

NHibernate homepage:
http://nhibernate.sourceforge.net/

Scott Bellware on NHibernate:
http://geekswithblogs.net/sbellware/archive/2004/12/19/18084.aspx
# February 15, 2005 8:25 AM

Wallym said:

Hey Jason. I've actually been involved with ADO.NET V2 Whidbey/Yukon for a while. I just haven't looked at the commandbuilder specifically as I prefer to write my own commands to send info back to the database. Here is the link to all my data access posts. I really like the async support (drool, drool). http://weblogs.asp.net/wallym/category/553.aspx

Wally
# February 17, 2005 7:59 AM

Wallym said:

Guru? Where, where. More like a legend, in my own mind.

Wally
# February 17, 2005 7:59 AM

weblogs.asp.net said:

372863.. Great idea :)

# June 25, 2011 2:16 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)