• linq 左连接三表筛选指定字段集合通过union连接单表筛选指定字段集合


    注意!

    左连接:是以左表为基础,根据ON后给出的两表的条件将两表连接起来。结果会将左表所有的查询信息列出,而右表只列出ON后条件与左表满足的部分。左连接全称为左外连接,是外连接的一种。

    左连接 linq:

    IQueryable<MenuDataModel> menus;
    
                 menus =  (from fu in _context.B2C_FUNCTIONLIST.Where(a => a.PARENT_FUNC != null).OrderBy(a => a.FUNCTIONID)
                           join gr in _context.B2C_GROUPFUNCTION on fu.FUNCTIONID equals gr.FUNCTIONID
                            join me in _context.B2C_MEMBERS.Where(a => a.USERNAME == userName)
                              on gr.GROUPID equals me.GROUP_ID
                            select new MenuDataModel
                            {
                                MenuId = fu.FUNCTIONID,
                                MenuName = fu.FUNCTIONNAME,
                                parent = fu.PARENT_FUNC,
                                url = fu.URL,
                                sortby = fu.SORTBY,
                                enabled = fu.ENABLED,
                            })

    通过 union 连接另一个集合,形成新的数据集合

    IQueryable<MenuDataModel> menus;
    
                 menus =  (from fu in _context.B2C_FUNCTIONLIST.Where(a => a.PARENT_FUNC != null).OrderBy(a => a.FUNCTIONID)
                           join gr in _context.B2C_GROUPFUNCTION on fu.FUNCTIONID equals gr.FUNCTIONID
                            join me in _context.B2C_MEMBERS.Where(a => a.USERNAME == userName)
                              on gr.GROUPID equals me.GROUP_ID
                            select new MenuDataModel
                            {
                                MenuId = fu.FUNCTIONID,
                                MenuName = fu.FUNCTIONNAME,
                                parent = fu.PARENT_FUNC,
                                url = fu.URL,
                                sortby = fu.SORTBY,
                                enabled = fu.ENABLED,
                            }).Union        //union连接  将两个集合进行合并操作,过滤相同的项 (查询字段需一致
                            (from f in _context.B2C_FUNCTIONLIST.Where(a => a.PARENT_FUNC ==null).OrderBy(a => a.FUNCTIONID)
                             select new MenuDataModel
                             {
                                 MenuId = f.FUNCTIONID,
                                 MenuName = f.FUNCTIONNAME,
                                 parent = f.PARENT_FUNC,
                                 url = f.URL,
                                 sortby = f.SORTBY,
                                 enabled = f.ENABLED,
    
                             });
  • 相关阅读:
    离线下载使用Google商店插件crx
    springboot thymeleaf 引入js
    如何保证系统重启,tomcat自动重启
    如何实现财务自由
    理财之道
    九大职场定律
    算法系列二:如何学习算法
    FastDFS结合Flask使用
    系统权限的实现
    正则表达式
  • 原文地址:https://www.cnblogs.com/lixia0604/p/13959701.html
Copyright © 2020-2023  润新知