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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:06:18+00:00 2026-06-13T12:06:18+00:00

In .NET4 MVC 4 using Code First I have two classes that form a

  • 0

In .NET4 MVC 4 using Code First I have two classes that form a many to many relationship.
How can I write a simple LINQ query to find all Games that have at least one or more genres from a given list of genres? (i.e. Retreive all games that are of the Strategy and/or Sandbox genre)

public class Game
{
    public int ID { get; set; }
    public virtual ICollection<Genre> Genres { get; set; }
}

public class Genre
{
    public int ID { get; set; }
    public virtual ICollection<Game> Games { get; set; }
}

Please note that I am using Code First so I have no access to the abstracted join table GenreGames.

I have tried the following to find a game that contains at least one genre ID from the array gid:

var gid = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var result = from g in unitOfWork.GameRepository.dbSet
             where (
                 from gen in unitOfWork.GenreRepository.dbSet
                 where gid.Contains(gen.ID)
                 select gen.ID
             ).Any()
             select g;

When retrieving the results

List<Game> similiarGames = result.ToList<Game>();

the following error comes up.

Unable to create a constant value of type ‘GratifyGaming.Domain.Models.Genre’. Only primitive types or enumeration types are supported in this context.

How can I get the results I want using only primitive or enumeration types? Is there a workaround?

  • 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-13T12:06:20+00:00Added an answer on June 13, 2026 at 12:06 pm

    Try this instead :

    var test = unitOfWork.GameRepository.dbSet
                             .Where(G => G.Genres.Where(genre => 
                                         gid.Contains(genre .ID)).Count() > 0);
    

    Good Luck !!

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

Sidebar

Related Questions

I'm using .net4.5rc with MVC4.0rc The code below is taken from a MVC webapi
We have an ASP.NET application on ASP.NET 4.0 using MVC 3 which uses Windows
I am using ASP.NET MVC 3 with .NET 4.0. I have a model on
I am using ASP.NET 4 and MVC and trying to add code to handle
I have an .Net 4, MVC 3 site that utilizes the jquery Colorbox plug
i have an MVC 3 site using asp.net 4 in my views i have
I've downloaded the mini profiler: http://code.google.com/p/mvc-mini-profiler/ I'm using ASP.net 4.0 with webforms (VS 2010).
We have an app in ASP.NET MVC 3 that, due to legacy and porting
I'm developing an application using ASP.NET 4 MVC 3. I'm using the default AspNetSqlMembershipProvider.
I am using ASP.Net 4.0 MVC to query active directory. I am trying 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.