예제 #1
0
		private SqlSelect VisitDefaultIfEmpty(Expression sequence)
		{
			SqlSelect select = this.VisitSequence(sequence);
			SqlAlias alias = new SqlAlias(select);
			SqlAliasRef aliasRef = new SqlAliasRef(alias);

			SqlExpression opt = new SqlOptionalValue(
				new SqlColumn(
					"test",
					_nodeFactory.Unary(SqlNodeType.OuterJoinedValue,
						_nodeFactory.Value(typeof(int?), _typeProvider.From(typeof(int)), 1, false, _dominatingExpression)
						)
					),
					_nodeFactory.Unary(SqlNodeType.OuterJoinedValue, aliasRef)
				);
			SqlSelect optSelect = new SqlSelect(opt, alias, _dominatingExpression);

			alias = new SqlAlias(optSelect);
			aliasRef = new SqlAliasRef(alias);

			SqlExpression litNull = _nodeFactory.TypedLiteralNull(typeof(string), _dominatingExpression);
			SqlSelect selNull = new SqlSelect(litNull, null, _dominatingExpression);
			SqlAlias aliasNull = new SqlAlias(selNull);

			SqlJoin join = new SqlJoin(SqlJoinType.OuterApply, aliasNull, alias, null, _dominatingExpression);

			return new SqlSelect(aliasRef, join, _dominatingExpression);
		}
예제 #2
0
 internal virtual SqlExpression VisitOptionalValue(SqlOptionalValue sov) {
     sov.HasValue = this.VisitExpression(sov.HasValue);
     sov.Value = this.VisitExpression(sov.Value);
     return sov;
 }
		private Type GenerateOptionalValue(SqlOptionalValue opt)
		{
			Diagnostics.Debug.Assert(opt.HasValue.ClrType == typeof(int?));

			Label labIsNull = gen.DefineLabel();
			Label labExit = gen.DefineLabel();

			Type actualType = this.Generate(opt.HasValue);
			Diagnostics.Debug.Assert(TypeSystem.IsNullableType(actualType));
			LocalBuilder loc = gen.DeclareLocal(actualType);
			gen.Emit(OpCodes.Stloc, loc);
			gen.Emit(OpCodes.Ldloca, loc);
			this.GenerateHasValue(actualType);
			gen.Emit(OpCodes.Brfalse, labIsNull);

			this.GenerateExpressionForType(opt.Value, opt.ClrType);
			gen.Emit(OpCodes.Br_S, labExit);

			gen.MarkLabel(labIsNull);
			this.GenerateConstant(opt.ClrType, null);

			gen.MarkLabel(labExit);
			return opt.ClrType;
		}
예제 #4
0
		internal override SqlExpression VisitOptionalValue(SqlOptionalValue sov)
		{
			if(_isDebugMode)
			{
				_commandStringBuilder.Append("opt(");
				this.Visit(sov.HasValue);
				_commandStringBuilder.Append(", ");
				this.Visit(sov.Value);
				_commandStringBuilder.Append(")");
				return sov;
			}
			else
			{
				throw Error.InvalidFormatNode("OptionalValue");
			}
		}
예제 #5
0
		internal override SqlExpression VisitOptionalValue(SqlOptionalValue sov)
		{
			SqlExpression hasValue = this.VisitExpression(sov.HasValue);
			SqlExpression value = this.VisitExpression(sov.Value);
			return new SqlOptionalValue(hasValue, value);
		}
예제 #6
0
		internal override SqlExpression VisitOptionalValue(SqlOptionalValue sov)
		{
			sov.HasValue = this.VisitNamedExpression(sov.HasValue, "test");
			sov.Value = this.VisitExpression(sov.Value);
			return sov;
		}
예제 #7
0
		internal override SqlExpression VisitOptionalValue(SqlOptionalValue sov)
		{
			bool saveCanJoin = this.canJoin;
			this.canJoin = false;
			try
			{
				return base.VisitOptionalValue(sov);
			}
			finally
			{
				this.canJoin = saveCanJoin;
			}
		}