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

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

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

获取表所有信息:

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

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

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

最后取得所有相关内容

List<BRShow> tt = list1;

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

上一篇:Here's to the crazy ones.


下一篇:Hadoop基础概念介绍