Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Linq contains/split problem

Linq contains/split problem

Scheduled Pinned Locked Moved LINQ
databasecsharplinqdata-structuressales
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TAK78
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups