Beispiel #1
0
        public override void Translate(MethodCallExpression m, TranslationState state, UniqueNameGenerator nameGenerator)
        {
            MemberExpression member   = (m.Object ?? m.Arguments[0]) as MemberExpression;
            IDbObject        dbBinary = null;

            if (member.Type == typeof(string))
            {
                var dbConstants = (IDbConstant)state.ResultStack.Pop();
                dbConstants.Val = $"%{dbConstants.Val}%";

                var dbExpression = (IDbSelectable)state.ResultStack.Pop();
                dbBinary = _dbFactory.BuildBinary(dbExpression, DbOperator.Like, dbConstants);
            }
            else if (member.Type.IsArray)
            {
                var dbConstants = (IDbConstant)state.ResultStack.Pop();

                var dbExpression = (IDbSelectable)state.ResultStack.Pop();
                var dbFunc       = _dbFactory.BuildFunc(SqlTranslationHelper.GetSqlOperator(DbOperator.Any), false, m.Method.ReturnType, dbExpression);
                dbBinary = _dbFactory.BuildBinary(dbConstants, DbOperator.Equal, dbFunc);
            }
            else
            {
                throw new NotSupportedException($"Type {member.Type} is not supported");
            }

            state.ResultStack.Push(dbBinary);
        }
        public override string ToString()
        {
            var left  = Left.ToString();
            var right = Right.ToString();
            var optr  = SqlTranslationHelper.GetSqlOperator(Operator);

            var result = $"{left} {optr} {right}";

            return(UseParentheses ? $"({result})" : result);
        }