SqlExpression select statement as key?

I have a requirement where I need to use the select statement generated from a SqlExpression as a type of a key to store the data retrieved from the DB for each specific query.

The ToSelectStatement() extension method on SqlExpression<T> returns a parameterized select statement. Normally this works perfectly, but as a key this type of SQL will not work correctly as they key needs to be more specific:

WHERE ("ProfileUpdateRequest"."AppUserId" = @0)

Is there any built-in method somewhere which can replace the parameters with the actual values? Or is this something I must implement myself?

Something like this should work yes?

        public static string ToUnparameterizedSelectStatement<T>(this SqlExpression<T> expression)
            string s = expression.ToSelectStatement();
            foreach (var p in expression.Params)
                s = s.Replace(p.ParameterName, p.Value.ToString());

            return s;

We’ve also added a SqlFilter option from v4.5.5+ on MyGet which you could use instead, an alternative is to use Custom SQL, e.g:

var q = db.From<Table>()
    .Where("AppUserId = {0}", value);

var results = db.Select(q);