Hello, Regex
Via three parameters on the provider, you can use Regular Expression to transform the naming of Tables, Views, Properties, and Stored Procedures without impacting the underlying data access or database naming. The configuration parameters are:
- regexMatchExpression (string)
- regexReplaceExpression (string)
- regexIgnoreCase (bool, default is false)
The setting of these values are pumped through the following method at code generation time:
public static string RegexTransform(string inputText, string matchString, string replaceString, bool caseSensitive) {
Regex rx;
if (caseSensitive) {
rx = new Regex(matchString);
} else { rx = new Regex(matchString, RegexOptions.IgnoreCase); } return rx.Replace(inputText, replaceString);
}
The more you know about Regular Expressions, the more you'll be able to do with this. However, even if you're not familiar with them, you can still use the settings to do simple replaces. For example, try the following provider against the Northwind database, and you'll see all references to "Product" become "Widget":
<add name="Northwind" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="Northwind"
generatedNamespace="Northwind" regexMatchExpression="Product" regexReplaceExpression="Widget"/>
More Regex...
Sometimes you might want to have more than one transformation rule, and we allow for that using regexDictionaryReplace, which follows a simple dictionary rule for defning replacements:
<SubSonicService defaultProvider="Northwind">
<providers>
<clear/>
<add name="Northwind"
type="SubSonic.SqlDataProvider, SubSonic"
connectionStringName="Northwind"
generatedNamespace="Northwind"
regexDictionaryReplace="Products,Widgets;Customer,Clients"
/>
Expression are evaluated in the order they are expressed, so think carefully about your order of operations. It should also be noted that while these examples are not showing "real" regular expression syntax, any standard .NET expression can be evaluated. If you're looking to get a better understanding of more complex scenarios, here's a great place to get started.
