user1263981
user1263981

Reputation: 3147

How to filter List with multiple 'and' 'or' conditions

I am trying to filter List on following SQL query format;

SQL

SELECT * FROM Tracker
 where (TrackProposalID = 6 and TrackRequestID = 0) or TrackRequestID = 16

Linq

I have tried this so far but getting syntax error;

listT = CType(listT.Where(Function(o) (o.TrackProposalID = 6 And o.TrackRequestID = 0) or (o.TrackRequestID = 16)).ToList 

Upvotes: 1

Views: 1148

Answers (4)

Bondaryuk Vladimir
Bondaryuk Vladimir

Reputation: 519

var result = listT.Where(x => x.TrackRequestID == 16 || (x.TrackProposalID == 6 &&  x.TrackRequestID == 0))

if you won't make ToList(). it will execute every calls to "result". so i recomend make ToList().

Upvotes: 0

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14604

Try this

listT = listT.Where(x=>(x.TrackProposalID == 6 && x.TrackRequestID == 0) || (x.TrackRequestID == 16).ToList();

Upvotes: 1

Nikola.Lukovic
Nikola.Lukovic

Reputation: 1325

var newList = listT.Where(x=>(x.TrackProposalID == 6 && x.TrackRequestID == 0) || x.TrackRequestID == 16).ToList();

Upvotes: 0

stefankmitph
stefankmitph

Reputation: 3306

in C#

listT = listT.Where(o => (o.TrackProposalID == 6 && o.TrackRequestID == 0) || o.TrackRequestID == 16).ToList();

Upvotes: 2

Related Questions