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,
    
                             });
  • 相关阅读:
    JQuery脚本-通过禁用按钮防止表单重复提交
    获得图片的圆形头像效果
    jquery通过submit()和serialize()提交表单
    nginx location 配置阐述优先级别使用说明
    友盟(Swift)-集成、统计用户数量、具体页面访问数量、具体按钮点击数量
    点击按钮,使按钮进行左右翻转动画
    清除指定区域
    语音播报-文字转系统声音
    颜色线性渐变-CAGradientLayer
    popover带箭头弹框
  • 原文地址:https://www.cnblogs.com/lixia0604/p/13959701.html
Copyright © 2011-2022 走看看