public LinqHandlerBuilder(IMartenSession session, Expression expression, ResultOperatorBase additionalOperator = null, bool forCompiled = false)
        {
            _session = session;
            Model    = forCompiled
                ? MartenQueryParser.TransformQueryFlyweight.GetParsedQuery(expression)
                : MartenQueryParser.Flyweight.GetParsedQuery(expression);

            if (additionalOperator != null)
            {
                Model.ResultOperators.Add(additionalOperator);
            }

            var storage = session.StorageFor(Model.SourceType());

            TopStatement = CurrentStatement = new DocumentStatement(storage);


            // TODO -- this probably needs to get fancier later when this goes n-deep
            if (Model.MainFromClause.FromExpression is SubQueryExpression sub)
            {
                readQueryModel(Model, storage, false, storage.Fields);
                readQueryModel(sub.QueryModel, storage, true, _session.Options.ChildTypeMappingFor(sub.QueryModel.SourceType()));
            }
            else
            {
                readQueryModel(Model, storage, true, storage.Fields);
            }
        }
Example #2
0
        public override Statement UseAsEndOfTempTableAndClone(IncludeIdentitySelectorStatement includeIdentitySelectorStatement)
        {
            var clone = new DocumentStatement(_storage)
            {
                SelectClause = SelectClause,
                Orderings    = Orderings,
                Mode         = StatementMode.Select,
                ExportName   = ExportName,
            };

            // Select the Ids only
            SelectClause = includeIdentitySelectorStatement;


            clone.Where = new InTempTableWhereFragment(includeIdentitySelectorStatement.ExportName, "id");
            Limit       = Offset = 0;

            return(clone);
        }