public void ResolveSubStatementReferenceExpression_CreatesEntityReference_ForEntities()
        {
            var entityDefinitionExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook));
            var sqlStatement = new SqlStatementBuilder(SqlStatementModelObjectMother.CreateSqlStatement_Resolved(typeof(Cook)))
            {
                SelectProjection = entityDefinitionExpression,
                DataInfo         = new StreamedSequenceInfo(typeof(Cook[]), Expression.Constant(new Cook()))
            }.GetSqlStatement();
            var tableInfo = new ResolvedSubStatementTableInfo("q0", sqlStatement);
            var sqlTable  = new SqlTable(tableInfo, JoinSemantics.Inner);

            var result = SubStatementReferenceResolver.ResolveSubStatementReferenceExpression(entityDefinitionExpression, tableInfo, sqlTable, _context);

            Assert.That(result, Is.TypeOf(typeof(SqlEntityReferenceExpression)));
            Assert.That(_context.GetSqlTableForEntityExpression((SqlEntityReferenceExpression)result), Is.SameAs(sqlTable));

            var expectedResult = entityDefinitionExpression.CreateReference("q0", tableInfo.SqlStatement.SelectProjection.Type);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
Example #2
0
        public virtual SqlEntityExpression ResolveEntityRefMemberExpression(SqlEntityRefMemberExpression expression, IJoinInfo joinInfo, IMappingResolutionContext context)
        {
            ArgumentUtility.CheckNotNull("expression", expression);
            ArgumentUtility.CheckNotNull("joinInfo", joinInfo);
            ArgumentUtility.CheckNotNull("context", context);

            var originatingSqlTable = context.GetSqlTableForEntityExpression(expression.OriginatingEntity);
            var join = originatingSqlTable.GetOrAddLeftJoin(joinInfo, expression.MemberInfo);

            join.JoinInfo = ResolveJoinInfo(join.JoinInfo, context);
            var sqlTableReferenceExpression = new SqlTableReferenceExpression(join);

            return((SqlEntityExpression)ResolveExpression(sqlTableReferenceExpression, context));
        }
Example #3
0
        public void ProcessNames_SqlEntityExpression()
        {
            var entityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook), "test2");
            var namedExpression  = new NamedExpression("test", entityExpression);

            var tableRegisteredForEntity = SqlStatementModelObjectMother.CreateSqlTable();

            _context.AddSqlEntityMapping(entityExpression, tableRegisteredForEntity);

            var result = _namedExpressionCombiner.ProcessNames(namedExpression);

            Assert.That(result, Is.Not.SameAs(namedExpression));
            Assert.That(result, Is.TypeOf(typeof(SqlEntityDefinitionExpression)));
            Assert.That(((SqlEntityDefinitionExpression)result).Name, Is.EqualTo("test_test2"));
            Assert.That(_context.GetSqlTableForEntityExpression((SqlEntityExpression)result), Is.SameAs(tableRegisteredForEntity));
        }
        public void ResolveEntityRefMemberExpression()
        {
            var kitchenCookMember         = typeof(Kitchen).GetProperty("Cook");
            var entityExpression          = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Kitchen));
            var entityRefMemberExpression = new SqlEntityRefMemberExpression(entityExpression, kitchenCookMember);
            var unresolvedJoinInfo        = SqlStatementModelObjectMother.CreateUnresolvedJoinInfo_KitchenCook();
            var fakeJoinInfo = SqlStatementModelObjectMother.CreateResolvedJoinInfo(typeof(Cook));

            _mappingResolutionContext.AddSqlEntityMapping(entityExpression, SqlStatementModelObjectMother.CreateSqlTable(typeof(Cook)));

            var fakeEntityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook));

            _resolverMock
            .Expect(
                mock =>
                mock.ResolveJoinInfo(
                    Arg <UnresolvedJoinInfo> .Matches(joinInfo => joinInfo.MemberInfo == kitchenCookMember), Arg <UniqueIdentifierGenerator> .Is.Anything))
            .Return(fakeJoinInfo);

            _resolverMock
            .Expect(
                mock =>
                mock.ResolveSimpleTableInfo(
                    Arg <IResolvedTableInfo> .Is.Anything,
                    Arg <UniqueIdentifierGenerator> .Is.Anything))
            .Return(fakeEntityExpression);

            var result = _stage.ResolveEntityRefMemberExpression(entityRefMemberExpression, unresolvedJoinInfo, _mappingResolutionContext);

            _resolverMock.VerifyAllExpectations();

            Assert.That(result, Is.SameAs(fakeEntityExpression));
            var sqlTable = _mappingResolutionContext.GetSqlTableForEntityExpression(entityRefMemberExpression.OriginatingEntity);

            Assert.That(sqlTable.GetJoin(kitchenCookMember), Is.Not.Null);
            Assert.That(sqlTable.GetJoin(kitchenCookMember).JoinInfo, Is.SameAs(fakeJoinInfo));
        }
    public virtual SqlEntityExpression ResolveEntityRefMemberExpression (SqlEntityRefMemberExpression expression, IJoinInfo joinInfo, IMappingResolutionContext context)
    {
      ArgumentUtility.CheckNotNull ("expression", expression);
      ArgumentUtility.CheckNotNull ("joinInfo", joinInfo);
      ArgumentUtility.CheckNotNull ("context", context);

      var originatingSqlTable = context.GetSqlTableForEntityExpression (expression.OriginatingEntity);
      var join = originatingSqlTable.GetOrAddLeftJoin (joinInfo, expression.MemberInfo);
      join.JoinInfo = ResolveJoinInfo (join.JoinInfo, context);
      var sqlTableReferenceExpression = new SqlTableReferenceExpression (join);
      
      return (SqlEntityExpression) ResolveExpression (sqlTableReferenceExpression, context);
    }