Yeah, you could copy the UserDefinedFunctionTransformer and use it / hook it up like we do in the integration tests. But mainly, it was intended to transparantly service LinqToSql in the LinqToSqlAdapter and its general purpose function API.
The more established way is to just do what we do with all the usages of SqlFunctionExpression (when you check for usages) to register functions for existing methods or you can go with MethodCallExpressionTransformerAttribute to hook up custom methods (works for extension/static/instance methods) with dedicated sql functions:
[MethodCallExpressionTransformer (typeof (MySqlFunctionTransformer))]
public static T MySqlFunction<T> (this T o, int arg1, string arg2, int arg3)
{
throw new NotImplementedException ("Never called in memory."); // or implement it to have the code also work in memory
}
private class MySqlFunctionTransformer: IExpressionTransformer<MethodCallExpression>
{
public ExpressionType[] SupportedExpressionTypes
{
get { return new[]{ExpressionType.Xyz}; }
}
public Expression Transform (MethodCallExpression methodCallExpression)
{
// The arguments are extracted from the call an match the requirements of the sql function
return new SqlFunctionExpression ("MYSQLFUNCTION", methodCallExpression.Arguments[0], methodCallExpression.Arguments[1], methodCallExpression.Arguments[2]);
}
}
It really depends on what you need: user-defined function support in the user domain, pre-defined functions for custom methods, or representing standard methods in .NET as sql functions.
Best regards, Michael