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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:09:02+00:00 2026-06-10T06:09:02+00:00

I am trying to get a Where In clause to work with linq to

  • 0

I am trying to get a Where In clause to work with linq to entities and have run into problems. My issue is that I have several lists of various entities and I would like to select a set of Game entities off of these lists essentially setting up a SQL WHERE IN clause for them. The issue is that the lists of entities are being compared to the game entity’s related entities which have a many to many relationship. I have done a lot of research and tried a bunch of solutions to solve this but just cannot get it quite right, I would really appreciate some help from the stackoverflow community.

Thanks in advance.

Edit:

I have tried doing this instead of the unions:

     var relatedGames = from game in ugdb.Games
                        where game.Developers.Any(d => relatedDevelopers.Any(r => r.DeveloperID == d.DeveloperID))
                        || game.Publishers.Any(d => relatedPublishers.Any(r => r.PublisherID == d.PublisherID))
                        || game.Genres.Any(d => relatedGenres.Any(r => r.GenreID == d.GenreID))
                        select game;

With both the unions and this I recieve the following error message:

base {System.SystemException} = {“Unable to create a constant value of type ‘UltimateGameDB.Domain.Entities.Developer’. Only primitive types (‘such as Int32, String, and Guid’) are supported in this context.”}

Does anyone have any idea how to go about doing this without

My current code:

  public IQueryable<Video> GetSimilarVideos(Guid videoId)
  {
     IQueryable<Video> result = null;
     List<Video> similarVideoList = null;

     Video currentVideo = ugdb.Videos.Find(videoId);

     List<Genre> relatedGenres = new List<Genre>();
     List<Developer> relatedDevelopers = new List<Developer>();
     List<Publisher> relatedPublishers = new List<Publisher>();

     foreach (var game in currentVideo.Games)
     {
        relatedDevelopers.AddRange(game.Developers);
        relatedPublishers.AddRange(game.Publishers);
        relatedGenres.AddRange(game.Genres);
     }

     relatedDevelopers = relatedDevelopers.Distinct().ToList<Developer>();
     relatedPublishers = relatedPublishers.Distinct().ToList<Publisher>();
     relatedGenres = relatedGenres.Distinct().ToList<Genre>();

     //This is the piece I am having trouble with!
     var relatedGames = from game in ugdb.Games
                        where game.Developers.Union(relatedDevelopers).Count() > 0
                          || game.Genres.Union(relatedGenres).Count() > 0
                          || game.Publishers.Union(relatedPublishers).Count() > 0
                        select game;

     foreach (var game in relatedGames)
     {
        similarVideoList.AddRange(game.Videos.Where(v => v.VideoType.Equals(currentVideo.VideoType)));
     }

     result = similarVideoList.Distinct().AsQueryable<Video>();

     return result;
  }
  • 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-06-10T06:09:04+00:00Added an answer on June 10, 2026 at 6:09 am

    You can’t pass local entities – they won’t translate to sql, in your case relatedDevelopers. There’s not a way for Linq to Entities to translate relatedDevelopers.Contains to a Sql IN.

    You can either cast the list of games and do the call in memory so that it’s not having to be translated into sql – this is easier, but if your database is huge, it could be bad to load it all, just add ToList() at the end of ugdb.Games

     var relatedGames = from game in ugdb.Games.ToList()
                        where game.Developers.Any(d => relatedDevelopers.Any(r => r.DeveloperID == d.DeveloperID))
                        || game.Publishers.Any(d => relatedPublishers.Any(r => r.PublisherID == d.PublisherID))
                        || game.Genres.Any(d => relatedGenres.Any(r => r.GenreID == d.GenreID))
                        select game;
    

    Alternatively, you can create a list of Id’s and pass that, as that’s a primitive type that SQL can recognize:

         var relatedDevelopers = currentVideo.Games.SelectMany( g => g.Developers ).Select( g => g.DeveloperID ).ToArray();
         var relatedPublishers = currentVideo.Games.SelectMany( g => g.Developers ).Select( g => g.DeveloperID ).ToArray();
         var relatedGenres = currentVideo.Games.SelectMany( g => g.Developers ).Select( g => g.DeveloperID ).ToArray();
    
    
         //This is the piece I am having trouble with!
         var relatedGames = from game in ugdb.Games
                            where game.Developers.Any( d => relatedDevelopers.Contains(d.DeveloperID) )
                            || game.Publishers.Any( d => relatedPublishers.Contains(d.PublisherID))
                            || game.Genres.Any( d => relatedGenres.Contains(d.GenreID) )
                            select game;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the WITH clause to work with merge in Oracle, but
I have a MySQL query that is trying to get all the Pages that
I am trying to get a query work! I have this query right here:
So I have been trying to get guard clauses to work with Caliburn.Micro and
Ive been trying to get OrderBy in a LINQ statement to work with an
I get an error com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'productId3' in 'where clause' when trying to
I am trying get Struts 2 and Tiles to work and I am using
Trying to get this expression to work, can someone look at it and tell
I am trying to make a LINQ statement where the where clause comes from
Ok i have an mvc app. and im trying to get my delete to

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.