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?


    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=>;
        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);



source to share

3 answers

would something like this be enough?

var data = collection.Where(
        t => startTimes.Contains(t.theTime) || 
        endTimes.Contains(t.theTime + theLength));




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);




proposedRequest.Where(pr => startTimesArray.Contains(pr.start) || endTimesArray.Contains(pr.start + pr.length));




All Articles