What's new with SubSonic...

May 21, 2007 02:49

For those of you who have made the shift from following the Change Sets to following Revisions, I thought I should provide an update on some of the recent changes in the code base. In the move to SubVersion, I kinda fell out of my groove of making a post for every check-in, so I'm playing a bit of catch-up now...

New Query Ordering Support

In addition to some recent bug fixes, Query now supports multiple by ORDER BY clauses via the new OrderByCollection. In addition, several overloaded ORDER_BY methods have been added, allowing use like the following:

Query qry = new Query("Products").WHERE("SupplierID", 2).ORDER_BY("UnitPrice").ORDER_BY("ReorderLevel");

Furthermore, the OrderBy methods, which are used internally to support ORDER_BY, now include PassedValue which allows arbitrary values to be passed as ordering specifiers. For example, you could use the following query to retrieve all Products in random order (in SQL Server):

Query qry = new Query("Products").ORDER_BY("newid()");

"Pre-programming" with Extended Properties

Now this is something that I'm really excited about. For several months now, going back to pre 1.0.6 days, I've been intrigued by the idea of using the Extended Properties capabilities in SQL Server to feed directives to SubSonic, allowing custom object level behavior without falling into mapping/configuration hell. Being unable to shake this thought, I finally decided to do something about it, which has lead to first stages of a new method for expanding customer behavior on SubSonic generated objects.

The concept is quite simple. Basically it involves establishing a set of directives that can be applied to tables and columns in SQL Server that SubSonic will process when generating the schema. For the first pass, I've set up five directives which can be used to override existing class and property naming. The five directives are: 

  • SSX_TABLE_CLASS_NAME_SINGULAR
  • SSX_TABLE_CLASS_NAME_PLURAL
  • SSX_TABLE_DISPLAY_NAME
  • SSX_COLUMN_DISPLAY_NAME
  • SSX_COLUMN_PROPERTY_NAME

So how would you go about using these? Just add the directive as an extended property on the given database object. For example, if I wanted any of my "Product" class name references to be "Widget", I could do the following:

Once these are set, you simply set the useExtendedProperties configuration parameter to true and SubSonic does the rest. Extended Properties are processed after other transformation, so the values set here are the final word, regardless of what Regular Expression transformations you may have configured elsewhere.

Now, you're probably saying to yourself:

Not another naming transformation mechanism!!!

Valid point.

The above examples are a bit misleading. While they represent a way to bypass the internal transformations and may prove useful in certain scenarios, they are meant more as starting point than as a demonstration of the intent of this functionality. The real utility will appear in later revisions, which will include directives to the Scaffolds to indicate that a specific column should be presented with a rich-text editor, or that it contains a binary image which should be decoded and presented in the GridView as a graphic, and in the editor as an upload control - just to provide a two examples. Pretty cool, huh?

So what directives should be added to this list? I've got a few ideas, but I'm sure you have more, so post away!


5 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Related posts

Comments

May 21. 2007 07:19

Haacked

That's very cool! I remember talking about that idea with Rob. Glad to see it happening!

Haacked

May 21. 2007 09:57

Eric Kemp

Yeah, we were talking about this for M2M mappings as well...

monk.thelonio.us/.../Change-Set-0704041.aspx

Eric Kemp

May 23. 2007 12:16

Mischa Kroon

Instead of:

Query qry = new Query("Products").WHERE("SupplierID", 2).ORDER_BY("UnitPrice").ORDER_BY("ReorderLevel");

Wouldn't this be better:
Query qry = new Query("Products").WHERE("SupplierID", 2).ORDER_BY("UnitPrice","ReorderLevel");


Also how do you set it to Desc instead of Asc

Mischa Kroon

May 25. 2007 16:07

Kurt

Extended attributes seem like a really good place to cram validation information, input masks, etc.

Kurt

February 13. 2008 00:27

Ben McIntyre

I know this is an old post, and I don't like to be the naysayer here, but wouldn't it make a lot more sense to store this info in database tables or an XML file rather than in the extended properties ?
I get the impression that these kind of properties were added to SQL server to facilitate GUI design for server tools (eg. I note that the size and position of graphical elements in SQL server views are kept here).
While it's kinda old fashioned, the table-based extended properties would be compatible across all data sources (even MS Excel !). I suppose it doesn't matter too much, but my point is that we almost need a new ExtendedDataPropertiesProvider to make that consistent.
We sooooo need these extended properties, why they weren't implemented about 10 years ago I'll never know.

Ben McIntyre

Ben McIntyre

Comments are closed