Unable to create a constant value – only primitive types

First way :

Remove ToList() in the first query.


//instead of retrieving mathings List, retrieve only the productIds you need (which are a List of Primitive types)
var productIdList = db.matchings
.Where(m => m.StoreId == StoreId)
.Select(x => x.ProductId)

var products = db.Products
.Where(p => productIdList


//other way
var produts = db.Products
             .Where(p => db.matchings
                        .Any(m => m.StoreId == StoreId && 
                             m.ProductId == p.ProductId)

Because I think you’re in linq2entities, and you’re using a List of Matchings in a query which is not possible (the title of your topic tend to make me believe that’s your problem).

Leave a Comment