Exemple #1
0
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull(expression, "expression");

                if (!_commandTree.Parameters.Any())
                {
                    var parameter = CreateParameter(expression.Value, expression.ResultType);

                    _commandText.Append(parameter.ParameterName);
                }
                else
                {
                    _commandText.Append(_sqlGenerator.WriteSql(expression.Accept(_sqlGenerator)));
                }
            }
Exemple #2
0
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull(expression, "expression");

                var parameter = CreateParameter(expression.Value, expression.ResultType);

                if (_createParameters)
                {
                    _commandText.Append(parameter.ParameterName);
                }
                else
                {
                    using (var writer = new SqlWriter(_commandText.InnerBuilder))
                    {
                        _sqlGenerator.WriteSql(writer, expression.Accept(_sqlGenerator));
                    }
                }
            }
Exemple #3
0
            public override void Visit(DbConstantExpression expression)
            {
                Check.NotNull(expression, "expression");

                var parameter = CreateParameter(expression.Value, expression.ResultType);

                if (_createParameters)
                {
                    if (_sqlGenerator.CharBoolModes[_sqlGenerator.CurrentColumn] && expression.ResultType.EdmType.Name == "Boolean")
                    {
                        Facet nullable;
                        bool  isNullable = expression.ResultType.Facets.TryGetValue("Nullable", false, out nullable) && (bool)nullable.Value;
                        if (isNullable)
                        {
                            _commandText.Append("(CASE WHEN ");
                            _commandText.Append(parameter.ParameterName);
                            _commandText.Append(" IS NULL THEN NULL ELSE ");
                        }
                        _commandText.Append("(CASE WHEN ");
                        _commandText.Append(parameter.ParameterName);
                        _commandText.Append(" = 1 ");
                        _commandText.Append(string.Format(CultureInfo.InvariantCulture, "THEN '{0}' ELSE '{1}' END) ", SqlProviderServices.CharBoolTrueChar, SqlProviderServices.CharBoolFalseChar));
                        if (isNullable)
                        {
                            _commandText.Append("END) ");
                        }
                    }
                    else
                    {
                        _commandText.Append(parameter.ParameterName);
                    }
                }
                else
                {
                    using (var writer = new SqlWriter(_commandText.InnerBuilder))
                    {
                        _sqlGenerator.WriteSql(writer, expression.Accept(_sqlGenerator));
                    }
                }
            }