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!