我正在尝试按以下SQL查询格式过滤List;
SQL
SELECT * FROM Tracker
where (TrackProposalID = 6 and TrackRequestID = 0) or TrackRequestID = 16
LINQ的
到目前为止我已经尝试了这个但是语法错误;
listT = CType(listT.Where(Function(o) (o.TrackProposalID = 6 And o.TrackRequestID = 0) or (o.TrackRequestID = 16)).ToList
答案 0 :(得分:2)
在C#中
listT = listT.Where(o => (o.TrackProposalID == 6 && o.TrackRequestID == 0) || o.TrackRequestID == 16).ToList();
答案 1 :(得分:1)
试试这个
listT = listT.Where(x=>(x.TrackProposalID == 6 && x.TrackRequestID == 0) || (x.TrackRequestID == 16).ToList();
答案 2 :(得分:0)
var newList = listT.Where(x=>(x.TrackProposalID == 6 && x.TrackRequestID == 0) || x.TrackRequestID == 16).ToList();
答案 3 :(得分:0)
var result = listT.Where(x => x.TrackRequestID == 16 || (x.TrackProposalID == 6 && x.TrackRequestID == 0))
如果你不打造ToList()。它将执行每次调用“结果”。所以我建议制作ToList()。