示例#1
0
        internal List <MaterialPriceListDataView> GetAllMaterialPriceList(ICollection <AbstractSearch> searchCriteria,
                                                                          DateTime?dateActiveTo,
                                                                          string sortExpression, string sortDirection)
        {
            List <MaterialPriceListDataView> listView = new List <MaterialPriceListDataView>();

            listView = (from mpl in this.dbContext.MaterialPriceLists
                        orderby mpl.DateFrom ascending
                        where (dateActiveTo.HasValue ?
                               ((!mpl.DateTo.HasValue && mpl.DateFrom <= dateActiveTo.Value) ||
                                (mpl.DateTo.HasValue && mpl.DateFrom <= dateActiveTo.Value && mpl.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        select new MaterialPriceListDataView
            {
                idMaterialPriceList = mpl.idMaterialPriceList,
                LME = mpl.LME,
                Premium = mpl.Premium,
                DateFrom = mpl.DateFrom,
                DateTo = mpl.DateTo
            }).ApplySearchCriterias(searchCriteria).ToList();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "DateFrom";
            }

            listView = OrderByHelper.OrderBy <MaterialPriceListDataView>(listView, sortExpression, sortDirection).ToList <MaterialPriceListDataView>();

            return(listView);
        }
示例#2
0
        internal List <AttachmentDataView> GetAccountingAttachmentList(ICollection <AbstractSearch> searchCriteria, string sortExpression, string sortDirection)
        {
            List <AttachmentDataView> list = (from a in dbContext.Attachments
                                              join kvAttachmentType in dbContext.KeyValues on a.idAttachmentType equals kvAttachmentType.idKeyValue
                                              join u in dbContext.Users on a.idUser equals u.idUser
                                              join p in dbContext.Persons on u.idPerson equals p.idPerson
                                              select new AttachmentDataView
            {
                idAttachment = a.idAttachment,
                idAttachmentType = a.idAttachmentType,
                idModule = a.idModule,
                Description = a.Description,
                AttachmentDate = a.AttachmentDate,
                idUser = a.idUser,
                Title = p.Title,
                FirstName = p.FirstName,
                LastName = p.LastName,
                AttachmentTypeName = kvAttachmentType.Name,
                idAttachmentTypeKeyType = kvAttachmentType.idKeyType
            }).ApplySearchCriterias(searchCriteria).ToList();

            list = OrderByHelper.OrderBy <AttachmentDataView>(list, sortExpression, sortDirection).ToList <AttachmentDataView>();

            return(list);
        }
        internal List <ProductivityAndScrapDataView> GetAllProductivityAndScrapList(ICollection <AbstractSearch> searchCriteria,
                                                                                    DateTime?dateActiveTo,
                                                                                    string sortExpression, string sortDirection)
        {
            List <ProductivityAndScrapDataView> listView = new List <ProductivityAndScrapDataView>();

            listView = (from ps in this.dbContext.ProductivityAndScraps
                        orderby ps.DateFrom ascending
                        where (dateActiveTo.HasValue ?
                               ((!ps.DateTo.HasValue && ps.DateFrom <= dateActiveTo.Value) ||
                                (ps.DateTo.HasValue && ps.DateFrom <= dateActiveTo.Value && ps.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        select new ProductivityAndScrapDataView
            {
                idProductivityAndScrap = ps.idProductivityAndScrap,
                DateFrom = ps.DateFrom,
                DateTo = ps.DateTo
            }).ApplySearchCriterias(searchCriteria).ToList();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "DateFrom";
            }

            listView = OrderByHelper.OrderBy <ProductivityAndScrapDataView>(listView, sortExpression, sortDirection).ToList <ProductivityAndScrapDataView>();

            return(listView);
        }
示例#4
0
        internal List <AverageOutturnOverTimeDataView> GetAllAverageOutturnOverTimeDataView(ICollection <AbstractSearch> searchCriteria,
                                                                                            DateTime?dateActiveTo,
                                                                                            string sortExpression, string sortDirection)
        {
            List <AverageOutturnOverTimeDataView> listView = new List <AverageOutturnOverTimeDataView>();

            listView = (from mpl in this.dbContext.AverageOutturnOverTimes
                        orderby mpl.DateFrom ascending
                        where (dateActiveTo.HasValue ?
                               ((!mpl.DateTo.HasValue && mpl.DateFrom <= dateActiveTo.Value) ||
                                (mpl.DateTo.HasValue && mpl.DateFrom <= dateActiveTo.Value && mpl.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        select new AverageOutturnOverTimeDataView
            {
                idAverageOutturnOverTime = mpl.idAverageOutturnOverTime,
                ValueOfPressSMS1 = mpl.ValueOfPressSMS1,
                ValueOfPressSMS2 = mpl.ValueOfPressSMS2,
                ValueOfPressBREDA = mpl.ValueOfPressBREDA,
                ValueOfPressFARREL = mpl.ValueOfPressFARREL,
                DateFrom = mpl.DateFrom,
                DateTo = mpl.DateTo
            }).ApplySearchCriterias(searchCriteria).ToList();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "DateFrom";
            }

            listView = OrderByHelper.OrderBy <AverageOutturnOverTimeDataView>(listView, sortExpression, sortDirection).ToList <AverageOutturnOverTimeDataView>();

            return(listView);
        }
        public IEnumerable <TEntity> Buscar(Expression <Func <TEntity, bool> > condition, string orderBy = "", string sortDirection = "", int take = 0, int skip = 0)
        {
            var query = _contexto.Set <TEntity>().Where(condition);//

            if (!string.IsNullOrEmpty(orderBy))
            {
                if (!string.IsNullOrEmpty(sortDirection))
                {
                    if (sortDirection == "asc")
                    {
                        query = OrderByHelper.OrderBy(query, orderBy);
                    }
                    else
                    {
                        query = OrderByHelper.OrderByDescending(query, orderBy);
                    }

                    if (take > 0)
                    {
                        query = query.Take(take);
                    }
                    if (skip > 0)
                    {
                        query = query.Skip(skip);
                    }
                }
            }
            return(query.AsNoTracking().ToList());
        }
示例#6
0
        public SearchResult <ItemMonitoramentoDTO> Buscar(Expression <Func <ItemMonitoramentoDTO, bool> > condition, string orderBy = "", string sortDirection = "", int take = 0, int skip = 0)
        {
            var query        = QueryBase().Where(condition);
            int totalRecords = query.Count();

            if (!string.IsNullOrEmpty(orderBy))
            {
                if (sortDirection == "asc")
                {
                    query = OrderByHelper.OrderBy(query, orderBy);
                }
                else
                {
                    query = OrderByHelper.OrderByDescending(query, orderBy);
                }

                if (take > 0)
                {
                    query = query.Take(take);
                }
                if (skip > 0)
                {
                    query = query.Skip(skip);
                }
            }



            return(new SearchResult <ItemMonitoramentoDTO>
            {
                Itens = query.ToList(),
                TotalRecords = totalRecords,
                RecordsPerPage = take
            });
        }
        internal List <CommissionsByAgentDataView> GetAllCommissionsByAgentsList(ICollection <AbstractSearch> searchCriteria,
                                                                                 DateTime?dateActiveTo,
                                                                                 string sortExpression, string sortDirection)
        {
            List <CommissionsByAgentDataView> listView = new List <CommissionsByAgentDataView>();

            listView = (from ca in this.dbContext.CommissionsByAgents
                        join kvA in this.dbContext.KeyValues on ca.idAgent equals kvA.idKeyValue
                        where (dateActiveTo.HasValue ?
                               ((!ca.DateTo.HasValue && ca.DateFrom <= dateActiveTo.Value) ||
                                (ca.DateTo.HasValue && ca.DateFrom <= dateActiveTo.Value && ca.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        orderby kvA.Name ascending, ca.DateFrom ascending
                        select new CommissionsByAgentDataView
            {
                idCommissionsByAgent = ca.idCommissionsByAgent,
                idAgent = ca.idAgent,
                AgentName = kvA.Name,
                FixedCommission = ca.FixedCommission,
                CommissionPercent = ca.CommissionPercent,
                DateFrom = ca.DateFrom,
                DateTo = ca.DateTo
            }).ApplySearchCriterias(searchCriteria).ToList <CommissionsByAgentDataView>();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "AgentName, DateFrom";
            }

            listView = OrderByHelper.OrderBy <CommissionsByAgentDataView>(listView, sortExpression, sortDirection).ToList <CommissionsByAgentDataView>();

            return(listView);
        }
示例#8
0
        internal List <SAPDataDataView> GetAllSAPData(ICollection <AbstractSearch> searchCriteria,
                                                      DateTime?dateActiveTo,
                                                      string sortExpression, string sortDirection)
        {
            List <SAPDataDataView> listView = new List <SAPDataDataView>();

            listView = (from sd in this.dbContext.SAPDatas
                        where (dateActiveTo.HasValue ?
                               ((!sd.DateTo.HasValue && sd.DateFrom <= dateActiveTo.Value) ||
                                (sd.DateTo.HasValue && sd.DateFrom <= dateActiveTo.Value && sd.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        orderby sd.DateFrom ascending
                        select new SAPDataDataView
            {
                idSAPData = sd.idSAPData,
                DateFrom = sd.DateFrom,
                DateTo = sd.DateTo
            }).ApplySearchCriterias(searchCriteria).ToList <SAPDataDataView>();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "DateFrom";
            }

            listView = OrderByHelper.OrderBy <SAPDataDataView>(listView, sortExpression, sortDirection).ToList <SAPDataDataView>();

            return(listView);
        }
示例#9
0
        internal List <DiePriceListDataView> GetAllDiePriceList(ICollection <AbstractSearch> searchCriteria,
                                                                DateTime?dateActiveTo,
                                                                string sortExpression, string sortDirection)
        {
            List <DiePriceListDataView> listView = new List <DiePriceListDataView>();

            listView = (from dpl in this.dbContext.DiePriceLists
                        join kvV in this.dbContext.KeyValues on dpl.idVendor equals kvV.idKeyValue
                        where (dateActiveTo.HasValue ?
                               ((!dpl.DateTo.HasValue && dpl.DateFrom <= dateActiveTo.Value) ||
                                (dpl.DateTo.HasValue && dpl.DateFrom <= dateActiveTo.Value && dpl.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        orderby kvV.Name ascending, dpl.DateFrom ascending
                        select new DiePriceListDataView
            {
                idDiePriceList = dpl.idDiePriceList,
                VendorName = kvV.Name,
                idVendor = dpl.idVendor,
                DateFrom = dpl.DateFrom,
                DateTo = dpl.DateTo
            }).ApplySearchCriterias(searchCriteria).ToList <DiePriceListDataView>();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "VendorName, DateFrom";
            }

            listView = OrderByHelper.OrderBy <DiePriceListDataView>(listView, sortExpression, sortDirection).ToList <DiePriceListDataView>();

            return(listView);
        }
示例#10
0
        private ICypherQuery <TResult> CreateCypherQuery(IQuery <TAggregate> query)
        {
            var session = CreateFluentQuery();
            var cypher  = GetDataset(session, (TQuery)query);

            cypher = OrderByHelper <TResult, TAggregate> .OrderBy(cypher, query);

            cypher = cypher.Skip(query.Skip).Limit(query.Take);
            Log(cypher);
            return(cypher);
        }
示例#11
0
        internal List <DiePriceListDetailDataView> GetAllDiePriceListDetails(ICollection <AbstractSearch> searchCriteria,
                                                                             DateTime?dateActiveTo,
                                                                             string sortExpression, string sortDirection)
        {
            List <DiePriceListDetailDataView> listView = new List <DiePriceListDetailDataView>();

            listView = (from dpld in this.dbContext.DiePriceListDetails
                        join dpl in this.dbContext.DiePriceLists on dpld.idDiePriceList equals dpl.idDiePriceList
                        join kvV in this.dbContext.KeyValues on dpl.idVendor equals kvV.idKeyValue into grV
                        from subV in grV.DefaultIfEmpty()
                        join kvNmCav in this.dbContext.KeyValues on dpld.idNumberOfCavities equals kvNmCav.idKeyValue into grNmCav
                        from subNmCav in grNmCav.DefaultIfEmpty()
                        join kvPrCat in this.dbContext.KeyValues on dpld.idProfileCategory equals kvPrCat.idKeyValue into grPrCat
                        from subPrCat in grPrCat.DefaultIfEmpty()
                        join kvPrCompl in this.dbContext.KeyValues on dpld.idProfileComplexity equals kvPrCompl.idKeyValue into grPrCompl
                        from subPrCompl in grPrCompl.DefaultIfEmpty()
                        where (dateActiveTo.HasValue ?
                               ((!dpl.DateTo.HasValue && dpl.DateFrom <= dateActiveTo.Value) ||
                                (dpl.DateTo.HasValue && dpl.DateFrom <= dateActiveTo.Value && dpl.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        orderby dpl.DateFrom ascending
                        select new DiePriceListDetailDataView
            {
                idDiePriceListDetail = dpld.idDiePriceListDetail,
                idDiePriceList = dpl.idDiePriceList,
                VendorName = (subV != null ? subV.Name : string.Empty),
                idVendor = dpl.idVendor,
                DateFrom = dpl.DateFrom,
                DateTo = dpl.DateTo,
                idNumberOfCavities = dpld.idNumberOfCavities,
                NumberOfCavitiesName = (subNmCav != null ? subNmCav.Name : string.Empty),
                idProfileCategory = dpld.idProfileCategory,
                ProfileCategoryName = (subPrCat != null ? subPrCat.Name : string.Empty),
                idProfileComplexity = dpld.idProfileComplexity,
                ProfileComplexityName = (subPrCompl != null ? subPrCompl.Name : string.Empty),
                DimensionA = dpld.DimensionA,
                DimensionB = dpld.DimensionB,
                Price = dpld.Price,
                Lifespan = dpld.Lifespan
            }).ApplySearchCriterias(searchCriteria).ToList <DiePriceListDetailDataView>();



            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "VendorName, DimensionA, DimensionB, ProfileComplexityName, ProfileCategoryName, NumberOfCavitiesName";
            }

            listView = OrderByHelper.OrderBy <DiePriceListDetailDataView>(listView, sortExpression, sortDirection).ToList <DiePriceListDetailDataView>();

            return(listView);
        }
示例#12
0
        internal List <ProfileSettingDataView> GetProfilesList(ICollection <AbstractSearch> searchCriteria, string sortExpression, string sortDirection)
        {
            List <ProfileSettingDataView> listView = new List <ProfileSettingDataView>();

            listView = (from ps in this.dbContext.ProfileSettings
                        //Profile Complexity
                        join kvPrCom in this.dbContext.KeyValues on ps.idProfileComplexity equals kvPrCom.idKeyValue into grPrCom
                        from subPrCom in grPrCom.DefaultIfEmpty()
                        //Profile type
                        join kvPT in this.dbContext.KeyValues on ps.idProfileType equals kvPT.idKeyValue into grPT
                        from subPT in grPT.DefaultIfEmpty()
                        //Profile category
                        join kvPC in this.dbContext.KeyValues on ps.idProfileCategory equals kvPC.idKeyValue into grPC
                        from subPC in grPC.DefaultIfEmpty()

                        select new ProfileSettingDataView
            {
                idProfileSetting = ps.idProfileSetting,
                ProfileName = ps.ProfileName,
                idProfileType = ps.idProfileType,
                idProfileCategory = ps.idProfileCategory,
                idProfileComplexity = ps.idProfileComplexity,
                hasA = ps.hasA,
                hasB = ps.hasB,
                hasC = ps.hasC,
                hasD = ps.hasD,
                hasS = ps.hasS,
                DiameterFormula = ps.DiameterFormula,
                idCreateUser = ps.idCreateUser,
                dCreate = ps.dCreate,
                idModifyUser = ps.idModifyUser,
                dModify = ps.dModify,
                ImagePath = ps.ImagePath,

                //NumberOfCavitiesName    = (subNC != null ? subNC.Name : string.Empty),
                ProfileCategoryName = (subPC != null ? subPC.Name : string.Empty),
                ProfileTypeName = (subPT != null ? subPT.Name : string.Empty),
                ProfileComplexityName = (subPrCom != null ? subPrCom.Name : string.Empty),
            }
                        ).ApplySearchCriterias(searchCriteria).OrderBy(z => z.ProfileTypeName).ThenBy(z => z.ProfileCategoryName).ThenBy(z => z.ProfileComplexityName).ToList <ProfileSettingDataView>();

            listView = OrderByHelper.OrderBy <ProfileSettingDataView>(listView, sortExpression, sortDirection).ToList <ProfileSettingDataView>();

            return(listView);
        }
        internal List <ProductivityAndScrapDetailDataView> GetAllProductivityAndScrapDetailList(ICollection <AbstractSearch> searchCriteria,
                                                                                                DateTime?dateActiveTo,
                                                                                                string sortExpression, string sortDirection)
        {
            List <ProductivityAndScrapDetailDataView> listView = new List <ProductivityAndScrapDetailDataView>();

            listView = (from psd in this.dbContext.ProductivityAndScrapDetails
                        join ps in this.dbContext.ProductivityAndScraps on psd.idProductivityAndScrap equals ps.idProductivityAndScrap
                        join kvCc in this.dbContext.KeyValues on psd.idCostCenter equals kvCc.idKeyValue
                        join pfs in this.dbContext.ProfileSettings on psd.idProfileSetting equals pfs.idProfileSetting into grPfs
                        from subPfs in grPfs.DefaultIfEmpty()
                        orderby ps.DateFrom ascending
                        where (dateActiveTo.HasValue ?
                               ((!ps.DateTo.HasValue && ps.DateFrom <= dateActiveTo.Value) ||
                                (ps.DateTo.HasValue && ps.DateFrom <= dateActiveTo.Value && ps.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        select new ProductivityAndScrapDetailDataView
            {
                idProductivityAndScrapDetail = psd.idProductivityAndScrapDetail,
                idProductivityAndScrap = psd.idProductivityAndScrap,
                DateFrom = ps.DateFrom,
                DateTo = ps.DateTo,
                idCostCenter = psd.idCostCenter,
                CostCenterName = kvCc.DefaultValue4,
                idProfileSetting = psd.idProfileSetting,
                ProfileSettingName = (subPfs != null ? subPfs.ProfileName : string.Empty),
                SumOfHours = psd.SumOfHours,
                SumOfConsumption = psd.SumOfConsumption,
                SumOfProduction = psd.SumOfProduction,
                ProductivityKGh = psd.ProductivityKGh,
                ScrapRate = psd.ScrapRate
            }).ApplySearchCriterias(searchCriteria).ToList();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "DateFrom";
            }

            listView = OrderByHelper.OrderBy <ProductivityAndScrapDetailDataView>(listView, sortExpression, sortDirection).ToList <ProductivityAndScrapDetailDataView>();

            return(listView);
        }
        /// <summary>
        /// 用于渲染订单页面
        /// </summary>
        /// <param name="queryParams"></param>
        /// <returns></returns>
        public JsonResult GetOrder(queryParam queryParams)
        {
            OrderManageDbContext db       = new OrderManageDbContext();
            DbSet <Order>        data     = db.Orders;
            List <Order>         dataRows = null;


            if (queryParams.sortName != null && queryParams.sortOrder != null)
            {
                dataRows = OrderByHelper <Order> .OrderBy(data, queryParams.sortName, queryParams.sortOrder).ToList();
            }
            else
            {
                dataRows = data.ToList();
            }
            var total = dataRows.Count;
            var rows  = dataRows.Skip(queryParams.offset).Take(queryParams.limit).ToList();

            return(Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet));
        }
        public SearchResult <TEntity> BuscaAvancada(Expression <Func <TEntity, bool> > condition, string orderBy = "", string sortDirection = "", int take = 0, int skip = 0)
        {
            var query = _contexto.Set <TEntity>().AsQueryable();

            if (condition != null)
            {
                query = query.Where(condition);
            }

            int totalRecords = query.Count();

            if (!string.IsNullOrEmpty(orderBy))
            {
                if (!string.IsNullOrEmpty(sortDirection))
                {
                    if (sortDirection == "asc")
                    {
                        query = OrderByHelper.OrderBy(query, orderBy);
                    }
                    else
                    {
                        query = OrderByHelper.OrderByDescending(query, orderBy);
                    }

                    if (take > 0)
                    {
                        query = query.Take(take);
                    }
                    if (skip > 0)
                    {
                        query = query.Skip(skip);
                    }
                }
            }
            return(new SearchResult <TEntity>
            {
                Itens = query.ToList(),
                TotalRecords = totalRecords,
                RecordsPerPage = take
            });
        }
示例#16
0
        internal List <SAPDataQuantityDataView> GetAllSAPDataQuantity(ICollection <AbstractSearch> searchCriteria,
                                                                      DateTime?dateActiveTo,
                                                                      string sortExpression, string sortDirection)
        {
            List <SAPDataQuantityDataView> listView = new List <SAPDataQuantityDataView>();

            listView = (from sdq in this.dbContext.SAPDataQuantities
                        join sd in this.dbContext.SAPDatas on sdq.idSAPData equals sd.idSAPData
                        join kvCc in this.dbContext.KeyValues on sdq.idCostCenter equals kvCc.idKeyValue
                        join kvQt in this.dbContext.KeyValues on sdq.idQuantityType equals kvQt.idKeyValue
                        where (dateActiveTo.HasValue ?
                               ((!sd.DateTo.HasValue && sd.DateFrom <= dateActiveTo.Value) ||
                                (sd.DateTo.HasValue && sd.DateFrom <= dateActiveTo.Value && sd.DateTo >= dateActiveTo.Value)) :
                               1 == 1)
                        orderby sd.DateFrom ascending
                        select new SAPDataQuantityDataView
            {
                idSAPDataQuantity = sdq.idSAPDataQuantity,
                idSAPData = sdq.idSAPData,
                idCostCenter = sdq.idCostCenter,
                CostCenterName = kvCc.Name,
                idQuantityType = sdq.idQuantityType,
                QuantityTypeName = kvQt.Name,
                ValueData = sdq.ValueData,
                DateFrom = sd.DateFrom,
                DateTo = sd.DateTo
            }).ApplySearchCriterias(searchCriteria).ToList <SAPDataQuantityDataView>();

            if (string.IsNullOrEmpty(sortExpression) || sortExpression == Constants.INVALID_ID_STRING)
            {
                sortDirection = string.Empty;

                sortExpression = "DateFrom";
            }

            listView = OrderByHelper.OrderBy <SAPDataQuantityDataView>(listView, sortExpression, sortDirection).ToList <SAPDataQuantityDataView>();

            return(listView);
        }
示例#17
0
        internal List <DieFormulaDataView> GetAllDieFormulaList(ICollection <AbstractSearch> searchCriteria, string sortExpression, string sortDirection)
        {
            List <DieFormulaDataView> listView = new List <DieFormulaDataView>();

            listView = (from df in this.dbContext.DieFormulas
                        //Number of cavities
                        join kvNC in this.dbContext.KeyValues on df.idNumberOfCavities equals kvNC.idKeyValue into grNC
                        from subNC in grNC.DefaultIfEmpty()
                        //Profile type
                        join kvPT in this.dbContext.KeyValues on df.idProfileType equals kvPT.idKeyValue into grPT
                        from subPT in grPT.DefaultIfEmpty()
                        //Profile category
                        join kvPC in this.dbContext.KeyValues on df.idProfileCategory equals kvPC.idKeyValue into grPC
                        from subPC in grPC.DefaultIfEmpty()

                        select new DieFormulaDataView
            {
                idDieFormula = df.idDieFormula,
                idNumberOfCavities = df.idNumberOfCavities,
                idProfileType = df.idProfileType,
                idProfileCategory = df.idProfileCategory,
                DieFormulaText = df.DieFormulaText,
                idCreateUser = df.idCreateUser,
                dCreate = df.dCreate,
                idModifyUser = df.idModifyUser,
                dModify = df.dModify,
                ImagePath = df.ImagePath,

                NumberOfCavitiesName = (subNC != null ? subNC.Name : string.Empty),
                ProfileCategoryName = (subPC != null ? subPC.Name : string.Empty),
                ProfileTypeName = (subPT != null ? subPT.Name : string.Empty),
            }
                        ).ApplySearchCriterias(searchCriteria).OrderBy(z => z.NumberOfCavitiesName).ThenBy(z => z.ProfileTypeName).ThenBy(z => z.ProfileCategoryName).ToList <DieFormulaDataView>();

            listView = OrderByHelper.OrderBy <DieFormulaDataView>(listView, sortExpression, sortDirection).ToList <DieFormulaDataView>();

            return(listView);
        }