private static Expression HandleUnion( EntityQueryModelVisitor entityQueryModelVisitor, UnionResultOperator unionResultOperator) => HandleSetOperation( entityQueryModelVisitor, unionResultOperator.Source2, entityQueryModelVisitor.LinqOperatorProvider.Union);
public void HandleResultOperator() { var resultOperator = new UnionResultOperator("x", typeof(int), ExpressionHelper.CreateExpression(typeof(int[]))); var preparedSource2Statement = SqlStatementModelObjectMother.CreateSqlStatement(); var preparedSource2Expression = new SqlSubStatementExpression(preparedSource2Statement); _stageMock .Expect(mock => mock.PrepareResultOperatorItemExpression(resultOperator.Source2, _context)) .Return(preparedSource2Expression); _handler.HandleResultOperator(resultOperator, _sqlStatementBuilder, UniqueIdentifierGenerator, _stageMock, _context); _stageMock.VerifyAllExpectations(); // Main functionality Assert.That(_sqlStatementBuilder.SetOperationCombinedStatements, Has.Count.EqualTo(1)); Assert.That(_sqlStatementBuilder.SetOperationCombinedStatements[0].SetOperation, Is.EqualTo(SetOperation.Union)); Assert.That(_sqlStatementBuilder.SetOperationCombinedStatements[0].SqlStatement, Is.SameAs(preparedSource2Statement)); // Data info Assert.That(_sqlStatementBuilder.DataInfo, Is.TypeOf(typeof(StreamedSequenceInfo))); Assert.That(((StreamedSequenceInfo)_sqlStatementBuilder.DataInfo).DataType, Is.EqualTo(typeof(IQueryable <>).MakeGenericType(typeof(int)))); Assert.That( ((StreamedSequenceInfo)_sqlStatementBuilder.DataInfo).ItemExpression, Is.EqualTo(new QuerySourceReferenceExpression(resultOperator))); // Everyone referencing the result operator should reference the (outer) select projection instead. Assert.That( _context.GetExpressionMapping(new QuerySourceReferenceExpression(resultOperator)), Is.SameAs(_sqlStatementBuilder.SelectProjection)); }
protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext) { var resultOperator = new UnionResultOperator(AssociatedIdentifier, ItemType, Source2); clauseGenerationContext.AddContextInfo(this, resultOperator); return(resultOperator); }
public void GetOutputDataInfo_AssignableSource2() { var resultOperator = new UnionResultOperator("i", typeof(object), Expression.Constant(new[] { "string" })); var cookExpression = Expression.Constant(null, typeof(Cook)); var input = new StreamedSequenceInfo(typeof(Cook[]), cookExpression); var result = resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedSequenceInfo))); Assert.That(result.DataType, Is.SameAs(typeof(IQueryable <object>))); }
public void TransformExpressions() { var oldExpression = ExpressionHelper.CreateExpression(); var newExpression = ExpressionHelper.CreateExpression(); var resultOperator = new UnionResultOperator("i", typeof(int), oldExpression); resultOperator.TransformExpressions(ex => { Assert.That(ex, Is.SameAs(oldExpression)); return(newExpression); }); Assert.That(resultOperator.Source2, Is.SameAs(newExpression)); }
public void GetConstantSource2_NoConstantExpression () { var resultOperator = new UnionResultOperator ("i", typeof (string), Expression.Parameter (typeof (IEnumerable<string>), "ss")); Assert.That ( () => resultOperator.GetConstantSource2(), Throws.ArgumentException .With.Message.EqualTo ( #if !NET_3_5 "The source2 expression ('ss') is no ConstantExpression, it is a TypedParameterExpression.\r\nParameter name: expression" #else "The source2 expression ('ss') is no ConstantExpression, it is a ParameterExpression.\r\nParameter name: expression" #endif )); }
public void HandleResultOperator_NonStatementAsSource2() { var resultOperator = new UnionResultOperator("x", typeof(int), Expression.Constant(new[] { 1, 2, 3 })); var preparedSource2Expression = ExpressionHelper.CreateExpression(typeof(int[])); _stageMock .Expect(mock => mock.PrepareResultOperatorItemExpression(resultOperator.Source2, _context)) .Return(preparedSource2Expression); Assert.That(() => _handler.HandleResultOperator(resultOperator, _sqlStatementBuilder, UniqueIdentifierGenerator, _stageMock, _context), Throws.TypeOf <NotSupportedException>() .With.Message.EqualTo( "The 'Union' operation is only supported for combining two query results, but a 'ConstantExpression' was supplied as the " + "second sequence: value(System.Int32[])")); }
public void HandleResultOperator_OrderingsWithTopInSource2_CausesMainStatementToBeMovedToSubStatement() { var sqlStatement = SqlStatementModelObjectMother.CreateMinimalSqlStatement(new SqlStatementBuilder { Orderings = { SqlStatementModelObjectMother.CreateOrdering() }, TopExpression = Expression.Constant(10) }); var resultOperator = new UnionResultOperator("x", typeof(int), new SqlSubStatementExpression(sqlStatement)); var stage = CreateDefaultSqlPreparationStage(); _handler.HandleResultOperator(resultOperator, _sqlStatementBuilder, UniqueIdentifierGenerator, stage, _context); AssertStatementWasMovedToSubStatement(_sqlStatementBuilder); }
public void GetConstantSource2_NoConstantExpression() { var resultOperator = new UnionResultOperator("i", typeof(string), Expression.Parameter(typeof(IEnumerable <string>), "ss")); Assert.That( () => resultOperator.GetConstantSource2(), Throws.ArgumentException .With.Message.EqualTo( #if !NET_3_5 "The source2 expression ('ss') is no ConstantExpression, it is a TypedParameterExpression.\r\nParameter name: expression" #else "The source2 expression ('ss') is no ConstantExpression, it is a ParameterExpression.\r\nParameter name: expression" #endif )); }
public void SetUp() { _source2 = Expression.Constant(new[] { 2 }); _resultOperator = new UnionResultOperator("itemName", typeof(int), _source2); }
public void GetConstantSource2_NoConstantExpression () { var resultOperator = new UnionResultOperator ("i", typeof (string), Expression.Parameter (typeof (IEnumerable<string>), "ss")); resultOperator.GetConstantSource2 (); }
public void SetUp () { _source2 = Expression.Constant (new[] { 2 }); _resultOperator = new UnionResultOperator ("itemName", typeof (int), _source2); }
public void TransformExpressions () { var oldExpression = ExpressionHelper.CreateExpression (); var newExpression = ExpressionHelper.CreateExpression (); var resultOperator = new UnionResultOperator ("i", typeof (int), oldExpression); resultOperator.TransformExpressions (ex => { Assert.That (ex, Is.SameAs (oldExpression)); return newExpression; }); Assert.That (resultOperator.Source2, Is.SameAs (newExpression)); }
protected override ResultOperatorBase CreateResultOperator (ClauseGenerationContext clauseGenerationContext) { var resultOperator = new UnionResultOperator (AssociatedIdentifier, ItemType, Source2); clauseGenerationContext.AddContextInfo (this, resultOperator); return resultOperator; }
public void GetOutputDataInfo_AssignableSource2 () { var resultOperator = new UnionResultOperator ("i", typeof (object), Expression.Constant (new[] { "string" })); var cookExpression = Expression.Constant (null, typeof (Cook)); var input = new StreamedSequenceInfo (typeof (Cook[]), cookExpression); var result = resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedSequenceInfo))); Assert.That (result.DataType, Is.SameAs (typeof (IQueryable<object>))); }
public void GetConstantSource2_NoConstantExpression() { var resultOperator = new UnionResultOperator("i", typeof(string), Expression.Parameter(typeof(IEnumerable <string>), "ss")); resultOperator.GetConstantSource2(); }