zoukankan      html  css  js  c++  java
  • .net Linq多表组合查询结果集

    背景:

    主流程表中包含员工ID及流程类型ID,在页面查看流程是需要显示员工姓名及流程名称

    操作:

     //先进行分页处理原始数据
                var result = from p in _dbContext.Set<BeWorkflowContent>()
                             select p;
                if (searchWhere != null)
                    result = result.Where(searchWhere);
                if (order != null)
                    result = result.OrderByDescending(order);
                rowCount = result.Count();
                
                //多表查询组装最后的数据模型
                var query = from a in result
                            join b in _dbContext.BeUser on a.UserId equals b.UserId
                            join c in _dbContext.BeWorkflow on a.WorkflowId equals c.WorkflowId
                            select new WorkFlowContentV()
                            {
                                CustomerName = a.CustomerName,
                                WorkflowContentId = a.WorkflowContentId,
                                CarType = a.CarType,
                                CarStyle = a.CarStyle,
                                CarLicense = a.CarLicense,
                                UserName = b.TrueName,
                                WorkflowName = c.WorkflowName
                            };
                return query.ToList();
    View Code

    PS:select new之后一定要加对应的类名,不然返回后就是对象转换时会有问题

  • 相关阅读:
    python--输出spwm的数组
    爬虫二:爬取糗事百科段子
    爬虫一:爬取信息
    Python中的切片操作
    JSON
    python 中的异常处理与种类
    register的功能
    static的功能
    网络安全的认识
    VMware5.5-vCenter Converter(转换)
  • 原文地址:https://www.cnblogs.com/yhnet/p/11975852.html
Copyright © 2011-2022 走看看