/// <summary>
            /// Query Function "GetCurrentApplication" of Action "GetApplicationName"
            /// </summary>
            public static RLApplicationRecordList datasetGetCurrentApplication(HeContext heContext, int maxRecords, IterationMultiplicity multiplicity, out long outParamCount, int qpinESpaceId)
            {
                // Query Iterations: Never {-unbound-}
                // Uses binary data: False
                if (multiplicity == IterationMultiplicity.Never)
                {
                    maxRecords = 1;
                }
                outParamCount = -1;
                CacheHelper myCacheHelper = new CacheHelper();

                myCacheHelper.AddValue(Global.eSpaceId);
                myCacheHelper.AddValue("8ncuMQL0nf3wuIPtCEpJMw");
                myCacheHelper.AddValue(heContext.AppInfo.Tenant.Id.ToString());
                myCacheHelper.AddValue(Convert.ToString(maxRecords));
                myCacheHelper.AddValue(Convert.ToString(qpinESpaceId));
                string cacheHash = myCacheHelper.GetHash();

                OutSystems.RuntimeCommon.Pair <RLApplicationRecordList, long> temp = RuntimeCache.Instance.Get(new CacheKey(cacheHash)) as OutSystems.RuntimeCommon.Pair <RLApplicationRecordList, long>;
                if (temp == null)
                {
                    bool          useMainTransaction = (multiplicity != IterationMultiplicity.Single || (maxRecords > 0 && maxRecords <= 150));
                    Transaction   trans          = useMainTransaction? DatabaseAccess.ForCurrentDatabase.GetRequestTransaction(): DatabaseAccess.ForCurrentDatabase.GetReadOnlyTransaction();
                    Command       sqlCmd         = trans.CreateCommand();
                    string        sql            = "";
                    StringBuilder selectBuilder  = new StringBuilder();
                    StringBuilder fromBuilder    = new StringBuilder();
                    StringBuilder whereBuilder   = new StringBuilder();
                    StringBuilder orderByBuilder = new StringBuilder();
                    StringBuilder groupByBuilder = new StringBuilder();
                    StringBuilder havingBuilder  = new StringBuilder();
                    selectBuilder.Append("SELECT ");
                    if (maxRecords > 0)
                    {
                        selectBuilder.Append("TOP (");
                        selectBuilder.Append(maxRecords);
                        selectBuilder.Append(") ");
                    }
                    selectBuilder.Append("NULL o0, ENApplication.[NAME] o1, NULL o2, NULL o3, NULL o4, NULL o5, NULL o6, NULL o7, NULL o8, NULL o9, NULL o10, NULL o11, NULL o12, NULL o13");
                    fromBuilder.Append(" FROM {Application} ENApplication");
                    whereBuilder.Append(" WHERE (");
                    if (qpinESpaceId != 0)
                    {
                        whereBuilder.Append("((ENApplication.[ENTRY_ESPACE_ID] = @qpinESpaceId) AND (ENApplication.[ENTRY_ESPACE_ID] IS NOT NULL))");
                        sqlCmd.CreateParameterWithoutReplacements("@qpinESpaceId", DbType.Int32, qpinESpaceId);
                    }
                    else
                    {
                        whereBuilder.Append("(ENApplication.[ENTRY_ESPACE_ID] IS NULL)");
                    }
                    whereBuilder.Append(" OR ");
                    if (qpinESpaceId != 0)
                    {
                        whereBuilder.Append("((ENApplication.[BACKOFFICE_ESPACE_ID] = @qpinESpaceId) AND (ENApplication.[BACKOFFICE_ESPACE_ID] IS NOT NULL))");
                        sqlCmd.CreateParameterWithoutReplacements("@qpinESpaceId", DbType.Int32, qpinESpaceId);
                    }
                    else
                    {
                        whereBuilder.Append("(ENApplication.[BACKOFFICE_ESPACE_ID] IS NULL)");
                    }
                    whereBuilder.Append(")");

                    sql = selectBuilder.ToString() + fromBuilder.ToString() + whereBuilder.ToString() + groupByBuilder.ToString() + havingBuilder.ToString() + orderByBuilder.ToString();
                    string advSql = sql;
                    sql = AppUtils.Instance.ReplaceEntityReferences(heContext, advSql);
                    sqlCmd.CommandText = sql;
                    try {
                        RLApplicationRecordList outParamList = new RLApplicationRecordList();
                        outParamList.Transaction = trans;
                        BitArray[] opt = new BitArray[1];
                        opt[0] = new BitArray(new bool[] {
                            true, false, true, true, true, true, true, true, true, true, true, true, true, true
                        });
                        outParamList.AllOptimizedAttributes = opt;
                        if (multiplicity == IterationMultiplicity.Multiple)
                        {
                            RLApplicationRecordList _tmp = new RLApplicationRecordList();
                            _tmp.Transaction            = trans;
                            _tmp.AllOptimizedAttributes = opt;
                            _tmp.MaxRecords             = maxRecords;
                            try {
                                DateTime startTime = DateTime.Now;
                                DatabaseAccess.ForCurrentDatabase.ExecuteQuery(sqlCmd, _tmp, "Query GetApplicationName.GetCurrentApplication.List");
                                int queryExecutionTime = Convert.ToInt32(DateTime.Now.Subtract(startTime).TotalMilliseconds
                                                                         );
                                RequestTracer reqTracer = RuntimePlatformUtils.GetRequestTracer();
                                if (reqTracer != null)
                                {
                                    reqTracer.RegisterQueryExecuted("312e77f2-f402-fd9d-f0b8-83ed084a4933", "GetApplicationName.GetCurrentApplication", "794c445f-f27d-4f61-b47a-0da71440df68", "ContactManager", queryExecutionTime, DateTime.Now);
                                }
                                outParamList = (RLApplicationRecordList)_tmp.Duplicate();
                                _tmp.CloseDataReader();
                                RuntimeCache.Instance.Add(new CacheKey(cacheHash), new OutSystems.RuntimeCommon.Pair <RLApplicationRecordList, long>((RLApplicationRecordList)(outParamList.Duplicate()), -1), new EspaceTenantDependency(Global.eSpaceId, Global.App.Tenant.Id), DateTime.UtcNow.AddMinutes(60), CacheUtils.NoSliding, OutSystems.RuntimeCommon.Caching.CacheItemPriority.Removable);
                                return(outParamList);
                            } finally {
                                _tmp.CloseDataReader();
                            }
                        }
                        else if (multiplicity == IterationMultiplicity.Never)
                        {
                            try {
                                DateTime startTime = DateTime.Now;
                                DatabaseAccess.ForCurrentDatabase.ExecuteQuery(sqlCmd, outParamList, "Query GetApplicationName.GetCurrentApplication.List");
                                int queryExecutionTime = Convert.ToInt32(DateTime.Now.Subtract(startTime).TotalMilliseconds
                                                                         );
                                RequestTracer reqTracer = RuntimePlatformUtils.GetRequestTracer();
                                if (reqTracer != null)
                                {
                                    reqTracer.RegisterQueryExecuted("312e77f2-f402-fd9d-f0b8-83ed084a4933", "GetApplicationName.GetCurrentApplication", "794c445f-f27d-4f61-b47a-0da71440df68", "ContactManager", queryExecutionTime, DateTime.Now);
                                }
                                outParamList.MaxRecords = maxRecords;
                                RuntimeCache.Instance.Add(new CacheKey(cacheHash), new OutSystems.RuntimeCommon.Pair <RLApplicationRecordList, long>((RLApplicationRecordList)(outParamList.Duplicate()), -1), new EspaceTenantDependency(Global.eSpaceId, Global.App.Tenant.Id), DateTime.UtcNow.AddMinutes(60), CacheUtils.NoSliding, OutSystems.RuntimeCommon.Caching.CacheItemPriority.Removable);
                                return(outParamList);
                            } finally {
                                outParamList.CloseDataReader();
                            }
                        }
                        else
                        {
                            if (maxRecords > 0 && maxRecords <= 150)
                            {
                                RLApplicationRecordList _tmp = new RLApplicationRecordList();
                                _tmp.Transaction            = trans;
                                _tmp.AllOptimizedAttributes = opt;
                                try {
                                    DateTime startTime = DateTime.Now;
                                    DatabaseAccess.ForCurrentDatabase.ExecuteQuery(sqlCmd, _tmp, "Query GetApplicationName.GetCurrentApplication.List");
                                    int queryExecutionTime = Convert.ToInt32(DateTime.Now.Subtract(startTime).TotalMilliseconds
                                                                             );
                                    RequestTracer reqTracer = RuntimePlatformUtils.GetRequestTracer();
                                    if (reqTracer != null)
                                    {
                                        reqTracer.RegisterQueryExecuted("312e77f2-f402-fd9d-f0b8-83ed084a4933", "GetApplicationName.GetCurrentApplication", "794c445f-f27d-4f61-b47a-0da71440df68", "ContactManager", queryExecutionTime, DateTime.Now);
                                    }
                                    outParamList = (RLApplicationRecordList)_tmp.Duplicate();
                                    outParamList.AllOptimizedAttributes = opt;
                                    _tmp.CloseDataReader();
                                    return(outParamList);
                                } finally {
                                    _tmp.CloseDataReader();
                                }
                            }
                            else
                            {
                                try {
                                    DateTime startTime = DateTime.Now;
                                    DatabaseAccess.ForCurrentDatabase.ExecuteQuery(sqlCmd, outParamList, "Query GetApplicationName.GetCurrentApplication.List");
                                    int queryExecutionTime = Convert.ToInt32(DateTime.Now.Subtract(startTime).TotalMilliseconds
                                                                             );
                                    RequestTracer reqTracer = RuntimePlatformUtils.GetRequestTracer();
                                    if (reqTracer != null)
                                    {
                                        reqTracer.RegisterQueryExecuted("312e77f2-f402-fd9d-f0b8-83ed084a4933", "GetApplicationName.GetCurrentApplication", "794c445f-f27d-4f61-b47a-0da71440df68", "ContactManager", queryExecutionTime, DateTime.Now);
                                    }
                                    outParamList.MaxRecords = maxRecords;
                                    RuntimeCache.Instance.Add(new CacheKey(cacheHash), new OutSystems.RuntimeCommon.Pair <RLApplicationRecordList, long>((RLApplicationRecordList)(outParamList.Duplicate()), -1), new EspaceTenantDependency(Global.eSpaceId, Global.App.Tenant.Id), DateTime.UtcNow.AddMinutes(60), CacheUtils.NoSliding, OutSystems.RuntimeCommon.Caching.CacheItemPriority.Removable);
                                    return(outParamList);
                                } finally {
                                    if (maxRecords == 1)
                                    {
                                        outParamList.CloseDataReader();
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        throw new DataBaseException("Error executing query.", e);
                    }
                }
                else
                {
                    lock (temp) {
                        return((RLApplicationRecordList)temp.First.Duplicate());
                    }
                }
            }