I’m getting an exception when the GetProducts() method is called below. I’m essentially trying to filter down my list of Products by what is available in the specified Country. There is a one to many relationship setup between a Product and a Country.
public static List<Product> GetProducts(Country country)
{
Context db = new Context();
return db.Products.Where(m => m.Countries.Contains(country)).ToList<Product>();
}
Unable to create a constant value of type
‘DataModels.Country’. Only primitive types or
enumeration types are supported in this context.
If I’m not going about this the right way, what is the best way to filter Products by the single selected Country?
You can only compare based on primitive types.
I would change it to use the
Anymethod. ReplaceIDwith the Country entity key (or a unique property)