Ejemplo n.º 1
0
        public virtual object ExecuteLinqCommand(LinqCommand command, bool withIncludes = true)
        {
            try {
                var result = _dataSource.ExecuteLinqCommand(this, command);
                switch (command.Operation)
                {
                case LinqOperation.Select:
                    Context.App.AppEvents.OnExecutedSelect(this, command);
                    if (withIncludes && (command.Includes?.Count > 0 || Context.HasIncludes()))
                    {
                        IncludeProcessor.RunIncludeQueries(command, result);
                    }
                    //Util.Throw("Include processor disabled.");
                    break;

                default:
                    Context.App.AppEvents.OnExecutedNonQuery(this, command);
                    NextTransactionId = Guid.NewGuid();
                    break;
                }
                return(result);
            } catch (Exception ex) {
                ex.AddValue("entity-command", command + string.Empty);
                ex.AddValue("parameters", command.ParamValues);
                throw;
            }
        }
Ejemplo n.º 2
0
        //TODO: test and fix the following:
        // Includes - when including child list, the list initialized only if it's not empty;
        //    if empty, it remains uninitialized, and on touch fwk fires select query with 0 results
        // Initially found in some external solution, seemed to be broken, but now maybe working. Needs to be retested!
        internal static void RunIncludeQueries(LinqCommand command, object mainQueryResult)
        {
            // initial checks if there's anything to run
            if (mainQueryResult == null)
            {
                return;
            }
            var session     = command.Session;
            var allIncludes = session.Context.GetMergedIncludes(command.Includes);

            if (allIncludes == null || allIncludes.Count == 0)
            {
                return;
            }
            var resultShape = GetResultShape(session.Context.App.Model, mainQueryResult.GetType());

            if (resultShape == QueryResultShape.Object)
            {
                return;
            }
            // Get records from query result
            var records = new List <EntityRecord>();

            switch (resultShape)
            {
            case QueryResultShape.Entity:
                records.Add(EntityHelper.GetRecord(mainQueryResult));
                break;

            case QueryResultShape.EntityList:
                var list = mainQueryResult as IList;
                if (list.Count == 0)
                {
                    return;
                }
                foreach (var ent in list)
                {
                    records.Add(EntityHelper.GetRecord(ent));
                }
                break;
            }//switch;
            // actually run the includes
            var entityType = records[0].EntityInfo.EntityType;
            var helper     = new IncludeProcessor(session, allIncludes);

            session.LogMessage("------- Running include queries   ----------");
            helper.RunIncludeQueries(entityType, records);
            session.LogMessage("------- Completed include queries ----------");
        }