日期:2014-05-20  浏览次数:20754 次

对集合进行筛选,是或的关系怎么处理
对集合进行多次Where,他们是and的关系,要想实现or的关系,就要在一行里写完,如果在多行里写,有什么简单的技巧么?
我知道 a or b 等于not( not a and not b)不过这样要对整个条件not一下,实现似乎比较麻烦,我写不出来。


------解决方案--------------------
支持下,关注中!
------解决方案--------------------
不知所云。。。。
------解决方案--------------------
.where(tb=>(id>0?表达式1:表达式2)) 其中表达式1 或 2根据需要其中一个用为真


------解决方案--------------------
嵌套实现
LINQ


------解决方案--------------------

------解决方案--------------------
可以使用Union变通的实现:
例如:
C# code

List<Employee> employee = new List<Employee>{
                new Employee{ID = 1,Name = "aaa",City = "x",Address = "ding",Value =100},
                 new Employee{ID = 2,Name = "bbb",City = "y",Address = "dang",Value =200},
                  new Employee{ID = 3,Name = "ccc",City = "z",Address = "kacha",Value =300},
            new Employee{ID = 4,Name = "ddd",City = "y",Address = "wag",Value =200},
                  new Employee{ID = 5,Name = "eee",City = "z",Address = "ping",Value =300}
            };

            var query = employee.Where(x=> x.Address.StartsWith("d") || x.Value == 300);
            var query1 = employee.Where(x => x.Address.StartsWith("d")).Union(employee.Where(x => x.Value == 300));
       

            foreach (var q in query)
            {
                Console.Write(q.Name.ToString() + "\r\n");
            }
            Console.WriteLine("-----------");
            foreach (var q in query1)
            {
                Console.Write(q.Name.ToString() + "\r\n");
            }

------解决方案--------------------
不明白啥意思
------解决方案--------------------
http://topic.csdn.net/u/20080912/10/2CBCF3AF-9AD7-42D4-BD16-2EA9B6E189AF.html