public InsertOperation(QueryProvider queryProvider, Expression <Func <T> > evaluator)
            : base(queryProvider)
        {
            int memberInitCount              = 0;
            ParameterExpression  parameter   = Expression.Parameter(typeof(T));
            List <SetDescriptor> descriptors = null;

            evaluator.Visit(
                delegate(MemberInitExpression ex) {
                if (memberInitCount > 0)
                {
                    return(ex);
                }
                memberInitCount++;
                descriptors = new List <SetDescriptor>();
                foreach (MemberAssignment assignment in ex.Bindings)
                {
                    var fieldInfo = TypeInfo.Fields.FirstOrDefault(a => a.UnderlyingProperty == assignment.Member);
                    if (fieldInfo == null)
                    {
                        if (assignment.Member.ReflectedType.IsAssignableFrom(TypeInfo.UnderlyingType))
                        {
                            var property = TypeInfo.UnderlyingType.GetProperty(assignment.Member.Name);
                            fieldInfo    = TypeInfo.Fields.FirstOrDefault(field => field.UnderlyingProperty == property);
                        }
                    }
                    descriptors.Add(
                        new SetDescriptor(fieldInfo, parameter, assignment.Expression));
                }
                return(ex);
            });
            AddKey(descriptors);
            setOperation = new SetOperation <T>(this, descriptors);
        }
Example #2
0
        public BulkUpdateOperation(IUpdatable <T> query)
            : base((QueryProvider)((Updatable <T>)query).Query.Provider)
        {
            var descriptors = new List <SetDescriptor>();
            var q           = (Updatable <T>)query;

            this.query = q.Query;
            foreach (var expression in q.Expressions)
            {
                var        lambda = (LambdaExpression)expression.Item1;
                Expression ex     = lambda.Body;
                var        ex1    = lambda.Body as UnaryExpression;
                if (ex1 != null && ex1.NodeType == ExpressionType.Convert)
                {
                    ex = ex1.Operand;
                }
                var member = (PropertyInfo)((MemberExpression)ex).Member;
                lambda = (LambdaExpression)expression.Item2;
                var propertyInfo = TypeInfo.Fields.FirstOrDefault(a => a.UnderlyingProperty == member);
                if (propertyInfo == null)
                {
                    if (member.ReflectedType.IsAssignableFrom(TypeInfo.UnderlyingType))
                    {
                        member       = TypeInfo.UnderlyingType.GetProperty(member.Name);
                        propertyInfo = TypeInfo.Fields.FirstOrDefault(field => field.UnderlyingProperty == member);
                    }
                }
                descriptors.Add(
                    new SetDescriptor(propertyInfo, lambda.Parameters[0], lambda.Body));
            }
            setOperation = new SetOperation <T>(this, descriptors);
        }
Example #3
0
        public BulkUpdateOperation(IQueryable <T> query, Expression <Func <T, T> > evaluator)
            : base((QueryProvider)query.Provider)
        {
            this.query = query;
            var memberInitCount = 0;
            var parameter       = evaluator.Parameters[0];
            List <SetDescriptor> descriptors = null;

            evaluator.Visit(
                delegate(MemberInitExpression ex) {
                if (memberInitCount > 0)
                {
                    return(ex);
                }

                memberInitCount++;
                descriptors = (from MemberAssignment assigment in ex.Bindings
                               select
                               new SetDescriptor(
                                   TypeInfo.Fields.First(a => a.UnderlyingProperty == assigment.Member), parameter, assigment.Expression)).
                              ToList();
                return(ex);
            });
            setOperation = new SetOperation <T>(this, descriptors);
        }
Example #4
0
 public BulkUpdateOperation(IQueryable <T> query, List <SetDescriptor> descriptors)
     : base((QueryProvider)query.Provider)
 {
     this.query   = query;
     setOperation = new SetOperation <T>(this, descriptors);
 }