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 7089069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:52:39+00:00 2026-05-28T07:52:39+00:00

Possible Duplicate: 'Contains()' workaround using Linq to Entities? Using LINQ in C#, I have

  • 0

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

Using LINQ in C#, I have the following problem;

I need to select rows from a big table, using 3 conditions:
– “schooljaar” needs to be a value, set before,
– “p_bamatype” needs to be a value NOT in a list defined in settings (this is a StringCollection)
– “p_stdgeb” needs to be a value NOT in a list defined in settings (this is also a StringCollection)

I have this code:

var set = (db.SA_Opleiding.Where(opleiding => opleiding.schooljaar == schooljaar
                                 &&
                                 !Properties.Settings.Default.Admin_Studiegebieden_Exclude.Cast
                                                           <string>().ToList().Contains(
                                                               opleiding.p_stdgeb.ToString())
                                 &&
                                 !Properties.Settings.Default.Admin_Studietypes_Exclude.Cast
                                                           <string>().ToList().Contains(
                                                               opleiding.p_bamatype.ToString()))
                          .Select(opleiding => new OpleidingModel()
                                    {
                                        Id = opleiding.p_opleiding,
                                        LanNames =
                                            new Dictionary
                                            <string, string>()
                                                {
                                                    {
                                                        "NL",
                                                        opleiding.
                                                        opleidingNL
                                                        },
                                                    {
                                                        "FR",
                                                        opleiding.
                                                        opleidingFR
                                                        },
                                                    {
                                                        "EN",
                                                        opleiding.
                                                        opleidingEN
                                                        }
                                                }
                                    }))
                         .ToList<OpleidingModel>();

        return set;

However, LINQ fails converting the Contains method. I read about others having the same issue, but I can’t seem to find a decent solution for this. Is there really any solution for the problem described? So what I exactly need is a NOT IN (collection of strings) LINQ equivalent.

  • 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-28T07:52:40+00:00Added an answer on May 28, 2026 at 7:52 am

    If one of the various duplicate answers doesn’t help, here is a link to one that might. It references an extension to Linq-to-entities:

    public static class QueryExtensions
    {
        public static IQueryable<TEntity> WhereIn<TEntity, TValue>
        (
            this ObjectQuery<TEntity> query,
            Expression<Func<TEntity, TValue>> selector,
            IEnumerable<TValue> collection
        )
        {
            ParameterExpression p = selector.Parameters.Single();
    
            //if there are no elements to the WHERE clause,
            //we want no matches:
            if (!collection.Any()) return query.Where(x=>false);
    
            if (collection.Count() > 3000) //could move this value to config
                throw new ArgumentException("Collection too large - execution will cause stack overflow", "collection");
    
            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));
        }
    }
    

    There are several others like it available.

    EDIT

    I’ve provided context for the code above, and here is possible usage:

    db.SA_Opleiding.WhereIn(v => v.SomeCollection);
    

    I haven’t ever used this specific extension method, but they’re all basically based on the same principle.

    • 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? I am using the System.Linq.Dynamic library
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: How can I lock a file using java (if possible) I have
Possible Duplicate: Ignore SVN files when exporting a WAR file from Eclipse? Using eclipse
Possible Duplicate: For loop and if statement Hi everyone, i have a following for
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
Possible Duplicate: Randomize a List<T> in C# I have a list which contains many
Possible Duplicate: JavaScript: string contains In the below code I have to check whether
Possible Duplicate: Custom Character recognition for android I have some camera shots which contains

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.