static TranslateResult <T> BuildPrivate <T>(ProjectionExpression proj)
        {
            var eagerChildProjections = EagerChildProjectionGatherer.Gatherer(proj).Select(cp => BuildChild(cp)).ToList();
            var lazyChildProjections  = LazyChildProjectionGatherer.Gatherer(proj).Select(cp => BuildChild(cp)).ToList();

            Scope scope = new Scope
            {
                Alias     = proj.Select.Alias,
                Positions = proj.Select.Columns.Select((c, i) => new { c.Name, i }).ToDictionary(p => p.Name, p => p.i),
            };

            Expression <Func <IProjectionRow, T> > lambda = ProjectionBuilder.Build <T>(proj.Projector, scope);

            var command = QueryFormatter.Format(proj.Select);

            var result = new TranslateResult <T>
            {
                EagerProjections     = eagerChildProjections,
                LazyChildProjections = lazyChildProjections,

                MainCommand = command,

                ProjectorExpression = lambda,

                Unique = proj.UniqueFunction,
            };

            return(result);
        }
Exemplo n.º 2
0
        static IChildProjection BuildChild(ChildProjectionExpression childProj)
        {
            var proj = childProj.Projection;

            Type type = proj.UniqueFunction == null?proj.Type.ElementType() !: proj.Type;

            if (!type.IsInstantiationOf(typeof(KeyValuePair <,>)))
            {
                throw new InvalidOperationException("All child projections should create KeyValuePairs");
            }

            Scope scope = new Scope(
                alias: proj.Select.Alias,
                positions: proj.Select.Columns.Select((c, i) => new { c.Name, i }).ToDictionary(p => p.Name !, p => p.i) /*CSBUG*/
                );


            var types = type.GetGenericArguments();

            var command = QueryFormatter.Format(proj.Select);

            if (childProj.IsLazyMList)
            {
                types[1] = types[1].GetGenericArguments()[0];
                return(giLazyChild.GetInvoker(types)(proj.Projector, scope, childProj.Token, command));
            }
            else
            {
                return(giEagerChild.GetInvoker(types)(proj.Projector, scope, childProj.Token, command));
            }
        }
Exemplo n.º 3
0
        static TranslateResult <T> BuildPrivate <T>(ProjectionExpression proj)
        {
            var eagerChildProjections = EagerChildProjectionGatherer.Gatherer(proj).Select(cp => BuildChild(cp)).ToList();
            var lazyChildProjections  = LazyChildProjectionGatherer.Gatherer(proj).Select(cp => BuildChild(cp)).ToList();

            Scope scope = new Scope(
                alias: proj.Select.Alias,
                positions: proj.Select.Columns.Select((c, i) => new { c.Name, i }).ToDictionary(p => p.Name !, p => p.i) /*CSBUG*/
                );

            Expression <Func <IProjectionRow, T> > lambda = ProjectionBuilder.Build <T>(proj.Projector, scope);

            var command = QueryFormatter.Format(proj.Select);

            var result = new TranslateResult <T>(

                eagerProjections: eagerChildProjections,
                lazyChildProjections: lazyChildProjections,

                mainCommand: command,
                projectorExpression: lambda,
                unique: proj.UniqueFunction
                );

            return(result);
        }
Exemplo n.º 4
0
        static internal string Format(Expression expression, out List<DbParameter> getParameters)
        {
            QueryFormatter qf = new QueryFormatter();
            qf.Visit(expression);

            getParameters = qf.parameterExpressions.Values.Select(pi => pi.Parameter).ToList();

            return qf.sb.ToString();
        }
Exemplo n.º 5
0
        static internal SqlPreCommandSimple Format(Expression expression)
        {
            QueryFormatter qf = new QueryFormatter();

            qf.Visit(expression);

            var parameters = qf.parameterExpressions.Values.Select(pi => pi.Parameter).ToList();

            return(new  SqlPreCommandSimple(qf.sb.ToString(), parameters));
        }
Exemplo n.º 6
0
        static internal SqlPreCommandSimple Format(Expression expression)
        {
            QueryFormatter qf = new QueryFormatter();

            qf.Visit(expression);

            var parameters = qf.parameterExpressions.Values.Select(pi => pi.Parameter).ToList();

            var sqlpc = new SqlPreCommandSimple(qf.sb.ToString(), parameters);

            return(PostFormatter.Value == null ? sqlpc : PostFormatter.Value.Invoke(sqlpc));
        }
 public static SqlPreCommandSimple BuildCommandResult(CommandExpression command)
 {
     return(QueryFormatter.Format(command));
 }