zoukankan      html  css  js  c++  java
  • 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,
    
                             });
  • 相关阅读:
    vue之路由的命名视图实现经典布局
    vue之路由的嵌套 子路由
    AngularJS阻止事件冒泡$event.stopPropagation()
    Vue之路由规则中定义参数 传参方式2 params
    前台页面中的Cookie存取删除,以及Cookie的跨域问题
    关于Cookie中的Expire问题和删除Cookie那点事儿
    4-索引中的那些操作
    3-在字符串内插中的神奇用法
    2-for循环之特别的写法与神奇的Override
    1-在C#中的数字 int double
  • 原文地址:https://www.cnblogs.com/lixia0604/p/13959701.html
Copyright © 2011-2022 走看看