private void MapStartsWithExpression(MethodCallExpression expression) { if ((expression.Arguments == null) || (expression.Arguments.Count != 1)) { throw new ApplicationException("Did not find exactly 1 Argument to StartsWith function"); } DbExpression srcExpression = GetDbExpressionForExpression(expression.Object); DbExpression dbExpression; if (expression.Arguments[0] is ConstantExpression) { var constantExpression = GetDbExpressionForExpression(expression.Arguments[0]) as DbConstantExpression; if ((constantExpression == null) || (constantExpression.Value == null)) { throw new NullReferenceException("Parameter to StartsWith cannot be null"); } dbExpression = srcExpression.Like(DbExpressionBuilder.Constant(constantExpression.Value.ToString() + "%")); } else { var argExpression = GetDbExpressionForExpression(expression.Arguments[0]); // Note: Can also do this using StartsWith function on srcExpression (which avoids having to hardcode the % character). // It works but generates some crazy conditions using charindex which I don't think will use indexes as well as "like"... //dbExpression = DbExpressionBuilder.Equal(DbExpressionBuilder.True, srcExpression.StartsWith(argExpression)); dbExpression = srcExpression.Like(argExpression.Concat(DbExpressionBuilder.Constant("%"))); } MapExpressionToDbExpression(expression, dbExpression); }