コード例 #1
0
		public static XElement GetFieldRef(ISpModelContext modelContext, Expression node)
		{
			if (node == null)
			{
				throw new ArgumentNullException("node");
			}

			node = node.StripQuotes();

			if (node.NodeType != ExpressionType.MemberAccess)
			{
				throw new NotSupportedException(string.Format("{0} should be a member access", node));
			}

			var memberExpression = (MemberExpression) node;
			var memberName = memberExpression.Member.Name;

			if (memberExpression.Expression.NodeType != ExpressionType.Parameter)
			{
				throw new NotSupportedException(string.Format("{0} not supported", memberExpression));
			}

			return new XElement(Tags.FieldRef,
				new XAttribute(Tags.Name, modelContext.GetSpFieldInternalName(memberExpression.Member.DeclaringType, memberName)));
		}
コード例 #2
0
ファイル: SelectBuilder.cs プロジェクト: reuzel/CqlSharp.Linq
        public ProjectionExpression UpdateSelect(ProjectionExpression projection, Expression selectExpression)
        {
            //get the lambda expression of the select method
            var lambda = (LambdaExpression)selectExpression.StripQuotes();

            //if the lambda, is the identity lamda, simply return
            if (lambda.IsIdentityLambda())
                return projection;

            //map the source argument of the lambda expression to the existing projection
            Map.Add(lambda.Parameters[0], projection.Projection);

            //get the new projection
            var newProjection = Visit(lambda.Body);

            //check if projection is actually changed
            if (newProjection == lambda.Body)
                return projection;

            //get used columns
            IEnumerable<SelectorExpression> columns = new ColumnFinder().FindColumns(newProjection);

            SelectStatementExpression select = projection.Select;
            var newSelect = new SelectStatementExpression(typeof(IEnumerable<>).MakeGenericType(newProjection.Type),
                                                          new SelectClauseExpression(columns.ToArray(),
                                                                                     select.SelectClause.Distinct),
                                                          select.TableName,
                                                          select.WhereClause,
                                                          select.OrderBy,
                                                          select.Limit,
                                                          select.AllowFiltering);
            
            return new ProjectionExpression(newSelect, newProjection, projection.Aggregator, false, projection.Consistency, projection.PageSize);
        }
コード例 #3
0
ファイル: WhereBuilder.cs プロジェクト: reuzel/CqlSharp.Linq
        public ProjectionExpression BuildWhere(ProjectionExpression projection, Expression whereClause)
        {
            //get the lambda expression of the select method
            var lambda = (LambdaExpression)whereClause.StripQuotes();

            //map the source argument of the lambda expression to the existing projection (the projection is what the where clause queries)
            Map.Add(lambda.Parameters[0], projection.Projection);

            if (projection.Select.WhereClause != null)
                _relations = new HashSet<RelationExpression>(projection.Select.WhereClause);
            else
                _relations = new HashSet<RelationExpression>();

            //get the new projections
            Expression expression = Visit(lambda.Body);

            if (!expression.IsTrue())
                throw new CqlLinqException("Where clause contains unsupported constructs");

            var select = projection.Select;

            var newSelectStmt = new SelectStatementExpression(select.Type,
                                                              select.SelectClause,
                                                              select.TableName,
                                                              _relations.ToArray(),
                                                              select.OrderBy,
                                                              select.Limit,
                                                              select.AllowFiltering);

            return new ProjectionExpression(newSelectStmt, projection.Projection,
                                            projection.Aggregator, projection.CanTrackChanges, projection.Consistency, projection.PageSize);
        }
コード例 #4
0
		private XElement VisitLimit(Expression node)
		{
			node = node.StripQuotes();

			if (node.NodeType != ExpressionType.Constant)
			{
				throw new NotSupportedException(string.Format("Limit {0} not supported", node));
			}

			var constExpression = (ConstantExpression) node;

			return new XElement(Tags.RowLimit, constExpression.Value);
		}
コード例 #5
0
		public static XElement GetValue(ISpModelContext modelContext, MemberExpression memberExpression, Expression node)
		{
			if (node == null)
			{
				throw new ArgumentNullException("node");
			}

			node = node.StripQuotes();

			if (node.NodeType != ExpressionType.Constant)
			{
				throw new NotSupportedException(string.Format("{0} should be a constant expression", node));
			}

			var constantExpression = (ConstantExpression)node;

			return new XElement(Tags.Value, 
				new XAttribute(Tags.Type, modelContext.GetSpFieldTypeAsString(memberExpression.Member.DeclaringType, memberExpression.Member.Name)),
				Convert.ToString(modelContext.ConvertToSpValue(memberExpression.Member.DeclaringType, memberExpression.Member.Name, constantExpression.Value)));
		}
コード例 #6
0
ファイル: OrderBuilder.cs プロジェクト: reuzel/CqlSharp.Linq
        public ProjectionExpression UpdateOrder(ProjectionExpression projection, Expression keySelectExpression,
                                                bool ascending)
        {
            //get the lambda expression of the select method
            var lambda = (LambdaExpression)keySelectExpression.StripQuotes();

            //map the source argument of the lambda expression to the existing projection
            Map.Add(lambda.Parameters[0], projection.Projection);

            //get the new projection
            var key = Visit(lambda.Body);

            //check if we are dealing with a column
            if ((CqlExpressionType)key.NodeType != CqlExpressionType.IdentifierSelector)
                throw new CqlLinqException("Select key in OrderBy does not map to table column");

            //get a reference to the select clause
            SelectStatementExpression select = projection.Select;

            //add the ordering to the list of orderBy clauses
            var ordering = new List<OrderingExpression>(select.OrderBy);
            ordering.Add(new OrderingExpression((SelectorExpression)key,
                                                ascending
                                                    ? CqlExpressionType.OrderAscending
                                                    : CqlExpressionType.OrderDescending));

            var newSelect = new SelectStatementExpression(select.Type,
                                                          select.SelectClause,
                                                          select.TableName,
                                                          select.WhereClause,
                                                          ordering,
                                                          select.Limit,
                                                          select.AllowFiltering);

            return new ProjectionExpression(newSelect, projection.Projection,
                                            projection.Aggregator, projection.CanTrackChanges, projection.Consistency, projection.PageSize);
        }
コード例 #7
0
		private IEnumerable<Expression> GetDistinctColumns(Expression expression)
		{
			var destType = expression.Type;
			if (!destType.IsComplexType())
				return new Expression[] { expression };

			var columns = DistinctColumnExtractor.GetDistinctColumns(mapper, expression.StripQuotes());

			columns = columns.Select(c => this.Visit(c)).ToList();

			return columns;
		}
コード例 #8
0
		protected LambdaExpression VisitSourceReferencedProjection(FromExpression from, Expression expression)
		{
			fromExpressions.Push(from);
			var projection = this.Visit(PartialEvaluator.Eval(expression.StripQuotes())) as LambdaExpression;
			fromExpressions.Pop();
			return projection;
		}