Reputation: 221
So I have the "Ever Expanding LINQ Query"... I found myself having to tack on a number of parameters and I'm getting crosseyed. I have this:
var ud = db.Updates
.Where(c => c.Sold.Equals(false)&&(c.Status.Equals(("Pending"))))
.GroupBy(c => c.Vehicle)
.Select(x => x
.OrderByDescending(y => y.TimeStamp)
.First())
.ToList();
And I need to add an OR to the "c.Status.Equals" to test for multiple string values... such as "Pending" || "Rejected" what's the right way/place to do this?
Thanks very much for any assistance!
Upvotes: 1
Views: 132
Reputation: 76557
You might want to consider storing an array of values to see if any of the constraints are met :
// Store all of the statuses you need to match within a collection
var validStatuses = new []{ "Pending", "Rejected", ... };
Then you would just need to update your Where()
clause to check if your existing status matched any of those within your previously defined collection :
db.Updates.Where(c => !c.Sold && validStatuses.Contains(c.Status)))
Upvotes: 11
Reputation: 11
Try to use || or operator
(c.Status.Equals(("Pending")|| c.Status.Equals("Rejected"));
Upvotes: 0
Reputation: 105
(c.Status.Equals("Pending") || c.Status.Equals("Rejected"))
var ud = db.Updates
.Where(c => c.Sold.Equals(false) &&(c.Status.Equals("Pending") || c.Status.Equals("Rejected")))
.GroupBy(c => c.Vehicle)
.Select(x => x.OrderByDescending(y => y.TimeStamp).First()).ToList();
Upvotes: 0