Example #1
0
 protected override NhLinqExpression PrepareQuery(Expression expression, out IQuery query)
 {
     expression = NhRelinqQueryParser.PreTransform(expression, _session.Factory);
     //  expression = new PlusMinusDurationMethodExpandingVisitor().Visit(expression);
     //expression = CompositeTypeExpandingVisitor.Rewrite(expression);
     expression = DateIntervalVisitor.Visit(expression, _session.Factory);
     expression = Blapp.Rewrite(expression, _session.Factory);
     return(base.PrepareQuery(expression, out query));
 }
Example #2
0
        private void AssertResult(
            IQueryable query,
            bool rewriteQuery,
            bool supported,
            string expectedEntityName,
            string expectedMemberPath,
            Predicate <IType> expectedMemberType,
            Predicate <IAbstractComponentType> expectedComponentType = null,
            bool nullability = true)
        {
            expectedComponentType = expectedComponentType ?? (o => o == null);

            var expression         = query.Expression;
            var preTransformResult = NhRelinqQueryParser.PreTransform(expression, new PreTransformationParameters(QueryMode.Select, Sfi));

            expression = preTransformResult.Expression;
            var constantToParameterMap = ExpressionParameterVisitor.Visit(preTransformResult);
            var queryModel             = NhRelinqQueryParser.Parse(expression);
            var requiredHqlParameters  = new List <NamedParameterDescriptor>();
            var visitorParameters      = new VisitorParameters(
                Sfi,
                constantToParameterMap,
                requiredHqlParameters,
                new QuerySourceNamer(),
                expression.Type,
                QueryMode.Select);

            if (rewriteQuery)
            {
                QueryModelVisitor.GenerateHqlQuery(
                    queryModel,
                    visitorParameters,
                    true,
                    NhLinqExpressionReturnType.Scalar);
            }

            var found = _tryGetMappedType(
                Sfi,
                queryModel.SelectClause.Selector,
                out var memberType,
                out var entityPersister,
                out var componentType,
                out var memberPath);

            Assert.That(found, Is.EqualTo(supported), $"Expression should be {(supported ? "supported" : "unsupported")}");
            Assert.That(entityPersister?.EntityName, Is.EqualTo(expectedEntityName), "Invalid entity name");
            Assert.That(memberPath, Is.EqualTo(expectedMemberPath), "Invalid member path");
            Assert.That(() => expectedMemberType(memberType), $"Invalid member type: {memberType?.Name ?? "null"}");
            Assert.That(() => expectedComponentType(componentType), $"Invalid component type: {componentType?.Name ?? "null"}");

            if (found)
            {
                Assert.That(_tryGetMappedNullability(Sfi, queryModel.SelectClause.Selector, out var isNullable), Is.True, "Expression should be supported");
                Assert.That(nullability, Is.EqualTo(isNullable), "Nullability is not correct");
            }
        }
Example #3
0
        public void ConstantInWhereDoesNotCauseManyKeys()
        {
            var q1 = (from c in db.Customers
                      where c.CustomerId == "ALFKI"
                      select c);
            var q2 = (from c in db.Customers
                      where c.CustomerId == "ANATR"
                      select c);
            var preTransformParameters = new PreTransformationParameters(QueryMode.Select, Sfi);
            var preTransformResult     = NhRelinqQueryParser.PreTransform(q1.Expression, preTransformParameters);
            var parameters1            = ExpressionParameterVisitor.Visit(preTransformResult);
            var k1 = ExpressionKeyVisitor.Visit(preTransformResult.Expression, parameters1, Sfi);

            var preTransformResult2 = NhRelinqQueryParser.PreTransform(q2.Expression, preTransformParameters);
            var parameters2         = ExpressionParameterVisitor.Visit(preTransformResult2);
            var k2 = ExpressionKeyVisitor.Visit(preTransformResult2.Expression, parameters2, Sfi);

            Assert.That(parameters1, Has.Count.GreaterThan(0), "parameters1");
            Assert.That(parameters2, Has.Count.GreaterThan(0), "parameters2");
            Assert.That(k2, Is.EqualTo(k1));
        }