Example #1
0
        /// <summary>
        /// The LoadOptionsCreating stage handler.
        /// </summary>
        /// <param name="e">
        /// The <see cref="LogicSoftware.DataAccess.Repository.Extended.Events.LoadOptionsCreatingEventArgs"/> instance containing the event data.
        /// </param>
        public override void OnLoadOptionsCreating(LoadOptionsCreatingEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            // getting all LoadWith expressions from tree and removing all LoadWith method calls
            e.Expression = this.Visit(e.Expression);

            foreach (LambdaExpression expression in this.LoadWithExpressions)
            {
                e.LoadOptions.LoadWith(expression);
            }
        }
Example #2
0
        /// <summary>
        /// Notifies interceptor about LoadOptionsCreating stage in query execution.
        /// </summary>
        /// <param name="e">
        /// The <see cref="LogicSoftware.DataAccess.Repository.Extended.Events.LoadOptionsCreatingEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// <c>true</c>, if at least one interceptor has been executed, <c>false</c> otherwise.
        /// </returns>
        public bool OnLoadOptionsCreating(LoadOptionsCreatingEventArgs e, QueryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // no suitable interceptors found
            if (context.Interceptors.Count == 0)
            {
                return(false);
            }

            // intercept
            context.Interceptors.ForEach(pair => pair.Value.OnLoadOptionsCreating(e));

            return(true);
        }
Example #3
0
        public TResult Execute <TResult>(QueryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.ExtensionsProvider.InitializeQueryContext(context);

            // first pass. processing all extension-specific method calls only
            Expression firstPassOutputExpression = this.Visit(context.Expression, context);

            // QueryCreating stage
            var queryCreating = new QueryCreatingEventArgs(firstPassOutputExpression);

            this.ExtensionsProvider.OnQueryCreating(queryCreating, context);

            // LoadOptionsCreating stage
            var loadOptionsCreating = new LoadOptionsCreatingEventArgs(queryCreating.Expression, new LoadOptions());

            this.ExtensionsProvider.OnLoadOptionsCreating(loadOptionsCreating, context);

            // getting original query from repository
            var originalQuery = this.Repository.All(context.ElementType, loadOptionsCreating.LoadOptions);

            // QueryCreated stage
            var queryCreated = new QueryCreatedEventArgs(originalQuery);

            this.ExtensionsProvider.OnQueryCreated(queryCreated, context);

            // concatenating expression after load options creating event with expression after query created event
            Expression readyToExecuteExpression = new ExpressionConstantReplacer(context.RootQuery, queryCreated.Query.Expression).Visit(loadOptionsCreating.Expression);

            // PreExecute stage
            var preExecute = new PreExecuteEventArgs(readyToExecuteExpression);

            this.ExtensionsProvider.OnPreExecute(preExecute, context);

            return(this.ExecuteCore <TResult>(originalQuery, context, preExecute.Expression));
        }
Example #4
0
 /// <summary>
 /// The LoadOptionsCreating stage handler.
 /// </summary>
 /// <param name="e">
 /// The <see cref="LogicSoftware.DataAccess.Repository.Extended.Events.LoadOptionsCreatingEventArgs"/> instance containing the event data.
 /// </param>
 /// <remarks>
 /// Base implementation is empty.
 /// </remarks>
 public virtual void OnLoadOptionsCreating(LoadOptionsCreatingEventArgs e)
 {
 }