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. Query from using a List

Query from using a List

Scheduled Pinned Locked Moved LINQ
databasedockerregexquestion
3 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I have a container that I want to query all elements that have a parameter that matches any of the items in a List. Do I have to loop through my list and requery every loop or can this be done in one line? e.g.

    List[int] matchingParams = GetMatchingParams();
    MyDataTable data = GetMyDataTable(); //Has an integer column we want to match to, lets call it intMatch

    var results = from rows in data
    where rows.intMatch == (ANY OF THE ITEMS IN matchingParams)
    select rows;

    I 1 Reply Last reply
    0
    • L Lost User

      I have a container that I want to query all elements that have a parameter that matches any of the items in a List. Do I have to loop through my list and requery every loop or can this be done in one line? e.g.

      List[int] matchingParams = GetMatchingParams();
      MyDataTable data = GetMyDataTable(); //Has an integer column we want to match to, lets call it intMatch

      var results = from rows in data
      where rows.intMatch == (ANY OF THE ITEMS IN matchingParams)
      select rows;

      I Offline
      I Offline
      Ian McCaul
      wrote on last edited by
      #2

      You may just be able to do a .Contains() i.e.:

      List[int] matchingParams = GetMatchingParams();
      MyDataTable data = GetMyDataTable(); //Has an integer column we want to match to, lets call it intMatch
      var results = from rows in data
      where matchingParams.Contains(rows.intMatch)
      select rows;

      L 1 Reply Last reply
      0
      • I Ian McCaul

        You may just be able to do a .Contains() i.e.:

        List[int] matchingParams = GetMatchingParams();
        MyDataTable data = GetMyDataTable(); //Has an integer column we want to match to, lets call it intMatch
        var results = from rows in data
        where matchingParams.Contains(rows.intMatch)
        select rows;

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Sweet! Thank you!:thumbsup:

        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