Esempio n. 1
0
        public ConstantProvider(QueryContext context, MemberExpression expr)
        {
            var constant = (ConstantExpression)expr.Expression;
            Value = constant.Type.GetField(expr.Member.Name).GetValue(constant.Value);

            ParamName = context.NextParam(this);
        }
Esempio n. 2
0
        public WhereConverter(Select select, QueryContext context)
        {
            if (select == null)
                throw new ArgumentNullException("select");

            if (context == null)
                throw new ArgumentNullException("context");

            _select = select;
            _context = context;
        }
Esempio n. 3
0
 public QueryConverter(QueryContext context)
 {
     _context = context;
 }
Esempio n. 4
0
        public bool VisitPath(QueryContext context, PropertyInfo[] path, out BracketedName alias, out PropertyMap map)
        {
            var entity = EntityMap;
            alias = Alias;
            map = null;

            for (var i = 0; i < path.Length - 1; i++)
            {
                var prop = path[i];
                var item = JoinGroup.FindJoin(prop);
                if (item == null)
                {
                    var reference = entity.FindReferenceMap(prop);

                    if (reference == null)
                        return false;

                    item = JoinGroup.AddJoin(alias, context.NextAlias(), reference);
                }

                alias = item.ToAlias;
                entity = item.ReferenceMap.To;
            }

            var last = path[path.Length - 1];
            map = entity.FindPropertyMap(last) ?? entity.FindReferenceMap(last);

            return true;
        }
Esempio n. 5
0
 public Select(QueryContext context)
     : this(context.GetEntityMap(context.EntityType), context.NextAlias())
 {
 }
Esempio n. 6
0
 public ParameterProvider(QueryContext context, ParameterExpression expr)
 {
     ExpressionName = expr.Name;
     ParamName = context.NextParam(this);
 }
Esempio n. 7
0
        public ConstantProvider(QueryContext context, object value)
        {
            Value = value;

            ParamName = context.NextParam(this);
        }
Esempio n. 8
0
        public ConstantProvider(QueryContext context, ConstantExpression expr)
        {
            Value = expr.Value;

            ParamName = context.NextParam(this);
        }
Esempio n. 9
0
        static string GetWhere(Expression<Func<Student, bool>> expr)
        {
            var convention = new DefaultConvention();
            var builder = new EntityMapBuilder<Student>(convention);

            var map = ((EntityMapBuilder<Student>)builder
                        .Key(_ => _.ID, "Student_id"))
                        .Build();

            var context = new QueryContext(new[]{map}, "");
            var selectEntity = new Select(map, "t0");
            var whereParser = new WhereConverter(selectEntity, context);

            var node = whereParser.Visit(expr);
            node.Render(context.Writer);
            var result = context.Writer.GetResult();

            return result;
        }