Linq contains/split problem
-
I wrote a query which selects products from a defined category and than groups them by there material and product: Dim prod = From x In (From m In db.Products _ Where m.Subclass.Contains(category) _ Select New With {.Material = m.Material, .MarketingTitle = m.Marketing_title, .MarketingTagline = m.Marketing_tagline, .IDKey = m.Idkey, .ProductPhoto = m.Product_photo}) _ Group x By x.Material, x.ProductPhoto Into mg = Group _ Select mg It works perfectly so far. The "Subclass" is a string which holds all the possible categories the product falls in: "1, 3, 5, 7" (each number is a Category ID from the Category table) When I use the query from above where for sample "category" = 1. Than it will select all products which contain "1" of course, which also includes "10" or "100". Now is there a way that I can split this string and loop through that array to find the exact match so in my sample exactly "1" and ignore others? Here is a query I was trying but doesn't work: Dim prod = From x In (From m In db.Products _ Let subCat = m.Subclass.Split(", ") _ Where subCat.Distinct().ToString = category _ Select New With {.Material = m.Material, .MarketingTitle = m.Marketing_title, .MarketingTagline = m.Marketing_tagline, .IDKey = m.Idkey, .ProductPhoto = m.Product_photo}) _ Group x By x.Material, x.ProductPhoto Into mg = Group _ Select mg Any suggestions are appreciated Thanks