Tony_89
Tony_89

Reputation: 817

Linq Query with array as parameter

I know this question is similar to others but they have not provided me with an answer so far. I have an array of numbers in javascript which i pass back to my controller, Each number is an id for an object in the db which i will pull out and load into a jqgrid. The issue im having is with the query. I pass back the array and then call the function below in my repository.

public IQueryable<IOSSample> getSamplesForSamplePoints(Array samplePointIds)
    {
        return (from u in context.IOSSamples
                where samplePointIds.Contains(u.IOSSamplingPointId)
                select u);
    }

However the function does not like me using contains so im not sure how to go about this, any help would be much appreciated.

Upvotes: 1

Views: 893

Answers (1)

Bruno
Bruno

Reputation: 4655

If u.IOSSamplingPointId is an int, you need to use a typed array as your function input parameter:

public IQueryable<IOSSample> getSamplesForSamplePoints(ICollection<int> samplePointIds)
{
    return (from u in context.IOSSamples
            where samplePointIds.Contains(u.IOSSamplingPointId)
            select u);
}

Upvotes: 3

Related Questions