protected override Expression VisitLambda <T>(Expression <T> node)
        {
            if (parameters == null || parameters.Count == 0)
            {
                return(new ObservableLambdaExpression <T>(node));
            }
            var parameterMappings = new Dictionary <string, object>(this.parameters);

            foreach (var par in node.Parameters)
            {
                parameterMappings.Remove(par.Name);
            }
            var visitor = new ApplyParametersVisitor(parameterMappings);
            var applied = visitor.Visit(node);

            return(new ObservableLambdaExpression <T>((Expression <T>)applied));
        }
        public INotifyExpression <T> CreateExpression <T>(Expression expression, IEnumerable <ParameterExpression> parameters, IDictionary <string, object> parameterMappings)
        {
            if (parameterMappings != null)
            {
                var applyParameters = new ApplyParametersVisitor(parameterMappings);
                expression = applyParameters.Visit(expression);
            }

            if (parameters == null || (parameterMappings == null ? !parameters.Any() : parameters.Count() == parameterMappings.Count))
            {
                var lambda = Expression.Lambda <Func <T> >(expression);
                return(new RepositoryAffectedNotifyValue <T>(Repository, lambda.Compile()));
            }
            else
            {
                return(new RepositoryAffectedNotifyFunc <T>(Repository, expression, parameters));
            }
        }
        public INotifyReversableExpression <T> CreateReversableExpression <T>(Expression expression, IEnumerable <ParameterExpression> parameters, IDictionary <string, object> parameterMappings)
        {
            if (parameterMappings != null)
            {
                var applyParameters = new ApplyParametersVisitor(parameterMappings);
                expression = applyParameters.Visit(expression);
            }

            if (parameters == null || (parameterMappings == null ? !parameters.Any() : parameters.Count() == parameterMappings.Count))
            {
                var lambda = Expression.Lambda <Func <T> >(expression);
                var setter = SetExpressionRewriter.CreateSetter(lambda);
                if (setter == null)
                {
                    throw new InvalidOperationException(string.Format("The lambda expression {0} could not be reversed.", expression));
                }
                return(new RepositoryAffectedReversableNotifyValue <T>(Repository, lambda.Compile(), setter.Compile()));
            }
            else
            {
                return(new RepositoryAffectedReversableNotifyFunc <T>(Repository, expression, parameters));
            }
        }