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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:06:50+00:00 2026-05-20T18:06:50+00:00

I am having trouble to return an IEnumerable and IList, I cant do it!

  • 0

I am having trouble to return an IEnumerable and IList, I cant do it!
I am using EF 4 with POCOs

Here’s the whole method:

//public IList<Genre> GetGenresByGame(int gameId)
public IEnumerable<Genre> GetGenresByGame(int gameId)
    {
        using(var ctx = new XContext())
        {
            var results =
                    from t0 in ctx.GameGenres
                    join t1 in ctx.GenreCultureDetails on t0.GenreId equals t1.GenreId
                    where t0.GameId == gameId && t1.CultureId == _cultureId
                    select new Genre
                    {
                        GenreId = t0.GenreId,
                        GenreName = t1.GenreName

                    };

            return results.ToList(); 
        }
    }

I have tried different ways that I have found on the net.. but can’t make it work!

Question 2:
I saw a screencast with Julie something, saying that “You should always return an ICollection” when using EF4.

Any thoughts about that ?

BR

EDIT:
When I load the page in Debug-mode i get these errors: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. OR The entity or complex type 'XModel.Genre' cannot be constructed in a LINQ to Entities query.

  • 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-20T18:06:50+00:00Added an answer on May 20, 2026 at 6:06 pm

    Genre must not be a L2EF type. Try this:

    public IEnumerable<Genre> GetGenresByGame(int gameId)
    {
        using(var ctx = new XContext())
        {
            var resultList =
                    from t0 in ctx.GameGenres
                    join t1 in ctx.GenreCultureDetails on t0.GenreId equals t1.GenreId
                    where t0.GameId == gameId && t1.CultureId == _cultureId
                    select new { t0.GenreId, t1.GenreName };
            var genres = resultList.AsEnumerable().Select(o => new Genre
                         {
                             GenreId = o.GenreId,
                             GenreName = o.GenreName
                         });
            return genres.ToList();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a little trouble with a method in which I use yield return
I'm having trouble with following linq2sql query: public IEnumerable List(IQueryable<Enquiry> enquiries, Supplier supplier) {
I've been having trouble getting the number of rows to return using mysqli. I
I'm having trouble with this class, in particular the method: public IQueryable<T> ExecuteOrderBys<T>(this IQueryable<T>
I'm having trouble understanding the behavior of the return built-in in Bash. Here is
I am having trouble constructing a single XPath statement to return two different sets
Im having trouble using a .NET COM in vb6, It compiles ok and I
I having trouble in dividing the HTML frames. I have been using the following
I'm having trouble reading a chunked response when using a StreamReader to read the
I'm having trouble writing a unit test for one of my controller actions. Here's

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.