问题:
一个List集合 SiemensShipmentWips里面有多个字段mawb,shipC、consC,RMB 四个字段。
需要根据字段mawb,shipC、consC 存在重复,并且RMB 小于5000金额的数据筛选出来。
请问使用LINQ语句如何编写查询条件?
回答1:
//先筛选出RMB<500的集合项,再进行字段重复筛选.
SiemensShipmentWips = SiemensShipmentWips.Where(x => x.RMB < 500);
var result = SiemensShipmentWips.Where(x=>
SiemensShipmentWips.Count(c=>c.mawb == x.mawb)>1 ||
SiemensShipmentWips.Count(c=>c.shipC == x.shipC)>1 ||
SiemensShipmentWips.Count(c=>c.consC == x.consC )>1 ||
);
回答2:
ssws.where(a=>(a.mawb==a.shipC||a.mawb==a.consC ||a.shipC==a.consC ||)&&a.rmb<5000)
回答3:
需要根据字段mawb,shipC、consC 存在重复 -----举个栗子
回答4:
感觉你这个意思是list去重吧?
回答5:
class Program
{
static void Main(string[] args)
{
List<Student> list = new List<Student>();
list.Add(new Student {
a="1",
b="2",
c="3",
rmb=10000
});
list.Add(new Student
{
a = "1",
b = "2",
c = "3",
rmb = 3000
});
list.Add(new Student
{
a = "1",
b = "2",
c = "3",
rmb = 5000
});
list.Add(new Student
{
a = "1",
b = "3",
c = "3",
rmb = 10000
});
var result = list.Where(t1 => list.Any(t2 => t1.a == t2.a && t1.b == t2.b && t1.c == t2.c && t1.rmb <= 5000)).ToList();
Console.Read();
}
}
public class Student
{
public string a { get; set; }
public string b { get; set; }
public string c { get; set; }
public int rmb { get; set; }
}
试试。。。。。。。。。。