Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 273667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:29:30+00:00 2026-05-12T00:29:30+00:00

I have a function where I get a list of ids, and I need

  • 0

I have a function where I get a list of ids, and I need to return the a list matching a description that is associated with the id. E.g.:

public class CodeData
{
    string CodeId {get; set;}
    string Description {get; set;}
}

public List<CodeData> GetCodeDescriptionList(List<string> codeIDs)
    //Given the list of institution codes, return a list of CodeData
    //having the given CodeIds
}

So if I were creating the sql for this myself, I would simply do something like the following (where the in clause contains all the values in the codeIds argument):

Select CodeId, Description FROM CodeTable WHERE CodeId IN ('1a','2b','3')

In Linq to Sql I can’t seem to find the equivalent of the “IN” clause. The best I’ve found so far (which doesn’t work) is:

 var foo = from codeData in channel.AsQueryable<CodeData>()
           where codeData.CodeId == "1" || codeData.CodeId == "2"
           select codeData;

The problem being, that I can’t dynamically generate a list of “OR” clauses for linq to sql, because they are set at compile time.

How does one accomplish a where clause that checks a column is in a dynamic list of values using Linq to Sql?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:29:31+00:00Added an answer on May 12, 2026 at 12:29 am

    Use

    where list.Contains(item.Property)
    

    Or in your case:

    var foo = from codeData in channel.AsQueryable<CodeData>()
              where codeIDs.Contains(codeData.CodeId)
              select codeData;
    

    But you might as well do that in dot notation:

    var foo = channel.AsQueryable<CodeData>()
                     .Where(codeData => codeIDs.Contains(codeData.CodeId));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get
I have the following function: //Function to get random number public static int RandomNumber(int
I have a view that contains a javascript function that i need to init/call
I have a list of user ids and want to get a few random
I have the following Oracle function: function get_job_no return number is V_job_no number; begin
I have a via with some jQuery function to get value from HTML element
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
I have a function that takes variadic arguments, that I obtain from func_get_args() .
I'm trying to get rid of floats in my functions. I have one function
hey guys, I am starting to get frustrated. I have a function I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.