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

  • SEARCH
  • Home
  • 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 1009659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:57:45+00:00 2026-05-16T08:57:45+00:00

Possible Duplicate: 'Contains()' workaround using Linq to Entities? I am using the System.Linq.Dynamic library

  • 0

Possible Duplicate:
'Contains()' workaround using Linq to Entities?

I am using the System.Linq.Dynamic library to power a GUI base query engine however I can’t seem to find support for the equivalent of the Sql IN operator. Has anyone used this?

I have searched and found a couple of possible duplicates here however none have been exactly what I am asking (or have been solved).

Clarification:

I am using the dynamic query API to build queries in Linq, e.g:

var customers = dbDataContext
                 .Clients
                 .Where("Lastname = @0", "Smith");

Which works fine, the one operator I am struggling with is an equivalent to the Sql IN operator. I would like to do this:

var customers = dbDataContext
                 .Clients
                 .Where("ProductIDsPurchased IN (1,6,8,90)");

However I am not sure how to write this using dynamic queries (the above does not work).

  • 1 1 Answer
  • 1 View
  • 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-16T08:57:46+00:00Added an answer on May 16, 2026 at 8:57 am

    Probably this Stackoverflow thread can help you…

    Excerpt from the thread:

    you could implement your own WhereIn method :

    public static IQueryable<TEntity> WhereIn<TEntity, TValue>
     (
         this ObjectQuery<TEntity> query, 
         Expression<Func<TEntity, TValue>> selector, 
         IEnumerable<TValue> collection
     )
    {
        if (selector == null) throw new ArgumentNullException("selector");
        if (collection == null) throw new ArgumentNullException("collection");
        ParameterExpression p = selector.Parameters.Single();
    
        if (!collection.Any()) return query;
    
        IEnumerable<Expression> equals = collection.Select(value => 
          (Expression)Expression.Equal(selector.Body, 
           Expression.Constant(value, typeof(TValue))));
    
        Expression body = equals.Aggregate((accumulate, equal) => 
        Expression.Or(accumulate, equal));
    
        return query.Where(Expression.Lambda<Func<TEntity, bool>>(body, p));
    }
    

    Usage:

    public static void Main(string[] args)
    {
        using (Context context = new Context())
        {
            //args contains arg.Arg
            var arguments = context.Arguments.WhereIn(arg => arg.Arg, args);   
        }
    }
    

    In your case:

    var customers = dbDataContext
                 .Clients
                 .WhereIn(c=> c.LastName, new List<string>{"Smith","Wesson"});
    

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: 'Contains()' workaround using Linq to Entities? Using LINQ in C#, I have
Possible Duplicate: How do I use LINQ Contains(string[]) instead of Contains(string) Suppose I have
Possible Duplicate: Linq to SQL “not like” operator How can I write a dynamic
Possible Duplicate: Rewriting URL that contains question mark Hi a noob question for url
Possible Duplicate: Is there a CSS parent selector? CSS selector for “foo that contains
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: Entity Framework with NOLOCK I'm using EF4 and .Net 4 to load
Possible Duplicate: hide row if it contains empty columns Can the row containing empty
Possible Duplicate: If string only contains spaces? I do not want to change a
Possible Duplicate: Regex.IsMatch vs string.Contains Which is faster, preferable and why? What the difference

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.