首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

LINQ里的Union和Concat,不管用,啥原因呢?该如何解决

2012-01-31 
LINQ里的Union和Concat,不管用,啥原因呢??.C# codeIListDepartmentTree list0 BLLDepartmentTree.Inst

LINQ里的Union和Concat,不管用,啥原因呢??.

C# code
        IList<DepartmentTree> list0 = BLLDepartmentTree.Instance.FindAll().Where(o => o.ID == 0).ToList();        this.Response.Write(string.Format("list0:{0};<br /><br />", list0.Count));        IList<DepartmentTree> list1 = BLLDepartmentTree.Instance.FindAll().Where(o => o.ID == 1).ToList();        list0.Concat(list1);        this.Response.Write(string.Format("list1:{0};<br />", list1.Count));        this.Response.Write(string.Format("list0:{0};<br /><br />", list0.Count));        IList<DepartmentTree> list2 = BLLDepartmentTree.Instance.FindAll().Where(o => o.ID == 5).ToList();        list0.Concat(list2);        this.Response.Write(string.Format("list2:{0};<br />", list2.Count));        this.Response.Write(string.Format("list0:{0};<br /><br />", list0.Count));


我是用的linq to object。为什么那个list0.Count搞来搞去,一直是 =1 呀。

list0.Concat(list1);我也用Union了,都不行呀。好像并没起到作用。啥原因呢?

PS:数据里绝对没出现相同的两行,可是我也用Concat了呀。麻烦各位看看呀,谢谢


[解决办法]
"o => o.ID == 0"

我没猜错的话,ID应该是你的主键。
那查出来Count结果不是1条记录是什么呢?
[解决办法]
C# code
            List<Myclass> result =                DataContext.Reward_award.Where(x => x.sports.Contains(strQuery)).Select(x => x).ToList();            List<Myclass> a = DataContext.Reward_award.Where("1=1").ToList();                        List<Myclass> bbb = result.Concat(a).ToList();
[解决办法]
list0.Concat(list1).TOList();
试试看。
[解决办法]
你犯了一个低级错误,你没有赋值。
list0=list0.Concat(list1).ToList();

热点排行