private SqlExpression BuildVersionFilter(PersistRequestBuilderContext context, SqlTableRef filteredTable, List <PersistParameterBinding> currentBindings)
        {
            SqlExpression result = null;

            foreach (var column in context.Type.GetVersionColumns())
            {
                var fieldIndex = GetFieldIndex(context.Type, column);
                if (!context.Task.AvailableFields[fieldIndex])
                {
                    continue;
                }
                PersistParameterBinding binding;
                if (!context.VersionParameterBindings.TryGetValue(column, out binding))
                {
                    var typeMapping = driver.GetTypeMapping(column);
                    binding = new PersistParameterBinding(typeMapping, fieldIndex, ParameterTransmissionType.Regular, PersistParameterBindingType.VersionFilter);
                    context.VersionParameterBindings.Add(column, binding);
                }
                var filteredColumn = filteredTable[column.Name];
                if (filteredColumn.IsNullReference())
                {
                    continue;
                }
                var filterValue = binding.ParameterReference;
                // Handle decimal precision issue
                if (Type.GetTypeCode(column.ValueType) == TypeCode.Decimal)
                {
                    filterValue = SqlDml.Cast(filterValue, driver.MapValueType(column));
                }
                result &= SqlDml.Variant(binding, filteredColumn == filterValue, SqlDml.IsNull(filteredColumn));
                currentBindings.Add(binding);
            }
            return(result);
        }
        protected override SqlExpression VisitUnary(UnaryExpression expression)
        {
            var operand = Visit(expression.Operand);

            if (expression.Method != null)
            {
                return(CompileMember(expression.Method, null, operand));
            }

            switch (expression.NodeType)
            {
            case ExpressionType.ArrayLength:
                if (expression.Operand.Type != typeof(byte[]))
                {
                    throw new NotSupportedException(string.Format(Strings.ExTypeXIsNotSupported, expression.Operand.Type));
                }
                return(SqlDml.Cast(SqlDml.BinaryLength(operand), driver.MapValueType(typeof(int))));

            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:
                return(SqlDml.Negate(operand));

            case ExpressionType.UnaryPlus:
                return(operand);

            case ExpressionType.Not:
                return(IsBooleanExpression(expression.Operand)
            ? SqlDml.Not(operand)
            : SqlDml.BitNot(operand));

            case ExpressionType.Convert:
            case ExpressionType.ConvertChecked:
                return(VisitCast(expression, operand));
            }
            return(operand);
        }
示例#3
0
 public BooleanExpressionConverter(StorageDriver driver)
 {
     booleanType = driver.MapValueType(typeof(bool));
 }
 public BooleanExpressionConverter(StorageDriver driver)
 {
     booleanType = driver.MapValueType(WellKnownTypes.Bool);
 }