zoukankan      html  css  js  c++  java
  • 从两个集合里排除重复的写法(适用:DB表和字段都很多,表间有关联的情况)

    获取其中一张表bulletinred为1的内容:

     1 public IList<BRShow> GetBulInfo()
     2         {
     3             var result = from a in ((Entities)this.DataContext).SPEPBULLETIN
     4                          join b in ((Entities)this.DataContext).USERS on a.USERID.ToUpper() equals b.ACCOUNT.ToUpper()
     5 
     6                          orderby a.POSTDATE descending
     7                          select new BRShow { ID = a.ID, TITLE = a.TITLE, NAME = b.NAME, POST_LEVEL = a.POST_LEVEL, POSTCONTENT = a.POSTCONTENT, POSTDATE = a.POSTDATE, bulletinread = 0 }; //查询出所有信息
     8 
     9             //20140402  By Xudaxia  遍历result,取得为1的条数
    10             var result2 = (from r in result
    11                            join b in ((Entities)this.DataContext).BULLETIN_RECORDS
    12                            on r.ID equals b.ID
    13                            select r).ToList();
    14             foreach (var r in result2) { r.bulletinread = 1; };
    15             return result2;
    16         }

    获取表所有信息:

     1 public IList<BRShow> GetBulInfo1()
     2         {
     3             var spepbulletins = ((Entities)this.DataContext).SPEPBULLETIN.ToList();
     4             var users = ((Entities)this.DataContext).USERS.ToList();
     5             var result = from a in spepbulletins
     6                          join b in users on a.USERID.ToUpper() equals b.ACCOUNT.ToUpper()
     7                          orderby a.POSTDATE descending
     8                          select new BRShow { ID = a.ID, TITLE = a.TITLE, NAME = b.NAME, POST_LEVEL = a.POST_LEVEL, POSTCONTENT = a.POSTCONTENT, POSTDATE = a.POSTDATE}; //查处所有信息(含未读和已读)
     9             return result.ToList();
    10         }

    在页面上调用,转为LIST后在所有信息中遍历取得ID,判断A表和B表的ID是否一致,如果一直则将bulletinred赋值为1

    1 List<BRShow> list = bulRep.GetBulInfo().ToList();//查处所有已读信息
    2         List<BRShow> list1 = bulRep.GetBulInfo1().ToList();
    3         foreach (BRShow b in list)
    4         {
    5             if (list1.Where(l => l.ID == b.ID).First() != null)
    6                 list1.Where(l => l.ID == b.ID).First().bulletinread = 1;
    7         }

    最后取得所有相关内容

    List<BRShow> tt = list1;

    ----附:欢迎大家提出更简便、性能更好的方法~

  • 相关阅读:
    => 运算符
    ASP.NET与Javascript中获取URL信息
    ASP.NET中存取图片到数据库的示例
    在C#中利用DirectX实现声音播放
    使用VS2005 DataSet设计器实现数据访问层
    用C#播放声音文件
    VB.NET中声音的播放
    用C#播放声音文件
    声音播放解决方案(C#)
    Asp.Net音频文件上传和播放
  • 原文地址:https://www.cnblogs.com/byvar/p/3645654.html
Copyright © 2011-2022 走看看