LINQ Where clause Multiple conditions
Im trying to get all rows of data containing a specific set of data.
There are some values in my database including start and length.
I have an array that contains integers called startTimes and another one called endTimes.
I need a where clause that will return records that have an initial value contained in startTimes, OR start + length contained in endTimes.
Is there a way to do this?
thank
IQueryable<request> proposedRequest = db.requests.Include(r => r.rooms);
proposedRequest = proposedRequest.Where(r=>r.booked.Equals(1));
proposedRequest = proposedRequest.Where(r=>r.roundID.Equals(roundID))8;
proposedRequest = proposedRequest.Where(r=>r.day.Equals(day));
int[] startTimes;
int[] endTimes;
for(var q=0;q<time;q++){
startTimes[startTimes.Length] = time + q;
endTimes[endTimes.Length] = time + q + 1;
}
proposedRequest = proposedRequest.Where(//what goes in here);
+3
source to share
3 answers
i has array startTime = [1,3,4] and array endTime = [2,4,5] lets say. I need to know if any of these values match my records? I don't think it did the job
To check if a value is in an int array, use the Contains method:
proposedRequest = proposedRequest.Where(s => startTimes.Contains(s.INT_ID)
|| endTimes.Contains(s.INT_ID));
Syntax: ARRAY.Contains(ID_TO_SEARCH)
it returns boolean:
var list = new List<int> {1,2,3,4,5};
var intVar = 4;
var exists = list.Contains(intVar);
+2
source to share