Example #1
0
            internal override NewExpression VisitNew(NewExpression nex)
            {
                // Allow creation of DataServiceCollection<T> objects in projections
                if (ResourceBinder.PatternRules.MatchNewDataServiceCollectionOfT(nex))
                {
                    // It doesn't matter if the DSC is being tracked or not, that has no direct effect on the projections
                    // But it does matter if the T in DSC<T> is an entity or not. In here we only allow entity types to be used
                    //   for creation of DSC.
                    if (ClientType.CheckElementTypeIsEntity(nex.Type))
                    {
                        foreach (Expression e in nex.Arguments)
                        {
                            // no need to check the constant values here (DataServiceContext, funcs, etc).
                            if (e.NodeType != ExpressionType.Constant)
                            {
                                base.Visit(e);
                            }
                        }

                        return nex;
                    }
                }

                throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, nex.ToString()));
            }
Example #2
0
            internal override NewExpression VisitNew(NewExpression nex)
            {
                // Allow creation of DataServiceCollection<T> objects in projections, stop others that project entities
                if (ClientType.CheckElementTypeIsEntity(nex.Type) &&
                    !ResourceBinder.PatternRules.MatchNewDataServiceCollectionOfT(nex))
                {
                    throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjection(this.type, nex.ToString()));
                }

                return base.VisitNew(nex);
            }
 internal override NewExpression VisitNew(NewExpression nex)
 {
     throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, SR.ALinqExpressionNotSupportedInProjectionToEntity, this.type, nex.ToString()));
 }
            internal override NewExpression VisitNew(NewExpression nex)
            {
                if (CommonUtil.IsClientType(nex.Type))
                {
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, SR.ALinqExpressionNotSupportedInProjection, this.type, nex.ToString()));
                }

                return base.VisitNew(nex);
            }
Example #5
0
 internal override NewExpression VisitNew(NewExpression nex)
 {
     if (ClientTypeUtil.TypeOrElementTypeIsEntity(nex.Type) && !ResourceBinder.PatternRules.MatchNewDataServiceCollectionOfT(nex))
     {
         throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, nex.ToString()));
     }
     return base.VisitNew(nex);
 }
Example #6
0
 internal override NewExpression VisitNew(NewExpression nex)
 {
     if (ResourceBinder.PatternRules.MatchNewDataServiceCollectionOfT(nex))
     {
         if (ClientTypeUtil.TypeOrElementTypeIsEntity(nex.Type))
         {
             foreach (Expression expression in nex.Arguments)
             {
                 if (expression.NodeType != ExpressionType.Constant)
                 {
                     base.Visit(expression);
                 }
             }
             return nex;
         }
     }
     else if (ResourceBinder.PatternRules.MatchNewCollectionOfT(nex) && !ClientTypeUtil.TypeOrElementTypeIsEntity(nex.Type))
     {
         foreach (Expression expression2 in nex.Arguments)
         {
             if (expression2.NodeType != ExpressionType.Constant)
             {
                 base.Visit(expression2);
             }
         }
         return nex;
     }
     throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, nex.ToString()));
 }
            internal override NewExpression VisitNew(NewExpression nex)
            {
                if (ResourceBinder.PatternRules.MatchNewDataServiceCollectionOfT(nex))
                {
                    if (ClientType.CheckElementTypeIsEntity(nex.Type))
                    {
                        foreach (Expression e in nex.Arguments)
                        {
                            if (e.NodeType != ExpressionType.Constant)
                            {
                                base.Visit(e);
                            }
                        }

                        return nex;
                    }
                }

                throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, nex.ToString()));
            }
        private void VisitNew(NewExpression node)
        {
            _constructor = node.Constructor;

            var type = node.Type;
            foreach (var parameter in node.Constructor.GetParameters())
            {
                MemberInfo member;
                if (node.Members != null)
                {
                    // anonymous types will have this set...
                    member = node.Members[parameter.Position];
                }
                else
                {
                    var members = type.GetMember(
                        parameter.Name,
                        MemberTypes.Field | MemberTypes.Property,
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);

                    if (members.Length != 1)
                    {
                        var message = string.Format("Could not find a member match for constructor parameter {0} on type {1} in the expression tree {2}.",
                            parameter.Name,
                            type.Name,
                            node.ToString());
                        throw new NotSupportedException(message);
                    }

                    member = members[0];
                }

                _mappings.Add(new ProjectionMemberMapping
                {
                    Expression = node.Arguments[parameter.Position],
                    Member = member,
                    Parameter = parameter
                });
            }
        }
Example #9
0
            private void GetNew(NewExpression newExpression)
            {
                foreach (var argument in newExpression.Arguments)
                {
                    GetOperandValue();
                }

                var args = newExpression.Arguments;

                var members = newExpression.Members;

                if (newExpression.Type != lambdaExpression.Body.Type)
                {

                    var lambdaHandler = new LambdaExpressionHandler(indentLevel + 1,
                                            Expression.Lambda(newExpression,
                                                Expression.Parameter(
                                                    lambdaExpression.Parameters[0].Type,
                                                    "source")));

                    foreach (var column in lambdaHandler.aliases)
                    {
                        aliases[lambaExpressionId + "." + column.Key] = column.Value;
                        aliases[column.Key] = column.Value;
                    }
                }
                else
                {

                    for (int i = 0; i < args.Count; i++)
                    {

                        if (args[i].NodeType != ExpressionType.MemberAccess ||
                            //hack - should check if MemberAccess has a corresponding column
                            // in db
                            !(args[i].Type.IsValueType || args[i].Type == typeof(string)))
                        {
                            continue;
                        }

                        string memberName = null;

                        if (newExpression.Members[i].Name.StartsWith("get_"))
                        {
                            memberName = newExpression.Members[i].Name.Substring(4);
                        }
                        else
                        {
                            memberName = newExpression.Members[i].Name;
                        }

                        var key = lambaExpressionId + "." + memberName;

                        aliases[key] = GetHashedName((args[i] as MemberExpression));
                    }
                }

                terms.Push(Expression.Constant(
                                new BoxedConstant(newExpression.ToString())));
            }