I am trying to perform a query using Linq, something I am new to. I would like to receive an array of IDs and retrieve the products with these IDs. The linq query I got to was this one:
public Product[] RetrieveProduct(int[] ids)
{
var query = from productInfos in productRepository.Table
where (ids.Contains(productInfos.Id))
&& productInfos.Active
select new ProductIndiInfo
{
ProductId = productInfos.Id,
CurrentPrice = productInfos.CurrentPrice
};
return query.ToArray();
}
But I keep receiving the famous exception:
{"Unable to create a constant value of type 'System.Int32[]'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."}
Some resources I read say that it is not available. But some others tell me it should work. I've seen many posts with alternatives here and in blogs and so on but it doesn't work. I am starting to think that this is a syntax issue...
I've also tried this approach:
var query = from productInfos in pricingInfoRepository.Table
where ids.Any(id => id == productInfos.ProductId)
&& productInfos.Active
select new PricingInfo
{
ProductId = productInfos.Id,
CurrentPrice = productInfos.CurrentPrice
};
return query.ToArray();
But I got the same issue.
Could someone please tell me if my syntax is wrong or if it is really a Linq problem? (Operation not supported?)
How do I find out which EF version I am using?
Update: As far as I understood, this question about the ids.Contains() would be a L2S question, but a possible answer would be that EF2 does not support it. Am I understanding it correctly?