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之后一定要加对应的类名,不然返回后就是对象转换时会有问题

  • 相关阅读:
    java中继承和多态的理解
    汽车租赁系统
    s2第六章继承和多态
    第三章泛型集合ArrayList 和Hashtable
    第二章项目总结
    s2第二章深入c#类型
    .NET平台
    航班查询系统
    java初始重点语法
    JDBC
  • 原文地址:https://www.cnblogs.com/yhnet/p/11975852.html
Copyright © 2011-2022 走看看