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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:42:18+00:00 2026-06-01T09:42:18+00:00

I am building a movie site. I am using mvc3 and entity framework. I

  • 0

I am building a movie site. I am using mvc3 and entity framework. I am using mostly LINQ to Entities to query the database. the site GUI is basically one view page which beside the first loading, I use mainly Ajax to refresh the movie list according to the search criteria and such. So I use one main query. when I check this at debug mode i see that query takes 10 seconds every time to perform, which is of course very slow. I have indexed the database according to my basic knowledge. here is the main query code:

 var casts = MovieCasts.Where(d => 
           movieIds.Contains(d.MovieId) 
           && d.WorkingTitleId != null &&             
           actorAndActressWtIds.Contains((int)d.WorkingTitleId)).AsEnumerable()
           .Where(d=>GetMoviesTop4CelebIds(d.MovieId).Contains(d.CelebId))
           .AsQueryable()
           .Select(d =>new MCast
           {
               MovieId = d.MovieId,
               Id = d.Id,
               CelebId = d.CelebId,
               CelebPageViews = d.Celebrity.PageViews,
               ActingParts = string.Join(",",d.ActingParts.Select(e => e.Name)),
               ActorName = HttpUtility.HtmlDecode(d.Celebrity.ShortName) ??             
                           HttpUtility.HtmlDecode(d.Celebrity.BirthName),
                           }).ToList(); 

the GetMoviesTop4CelebIds() is a function that approaches the database directly and returns a short list of int (celebId) according to the movie Id. This is why I used the first AsEnumerable(), otherwise it gave error “LINQ to Entities does not recognize the method and cannot translate…”
(a funny thing I should mention is that my code is slow in debug mode when I use break points and is fast without it. this is in development. In production the code is very slow.)
can anyone please help me to shade some light on the code? I would really love and need to improve the performance.

  • 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-01T09:42:19+00:00Added an answer on June 1, 2026 at 9:42 am

    Calling AsEnumerable() will execute the Linq to Entities query at that point and cause the rest of the operation to be performed using Linq to Objects. Try executing GetMoviesTop4CelebIds() separately before you execute this query and using the resultant values in the query instead of the method call.

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

Sidebar

Related Questions

I'm building a movie database with two tables, one containing movie names and the
building a site using PHP and MySQL that needs to store a lot of
I am building site using Amazon affiliate. Most of their widgets are <objects> and
We're building a site that will have very minimal code, it's mostly just going
I'm building a site with an embedded Youtube player using JSF. I want to
I am building an ASP.NET site using Visual Studio 2008 and have a page
I'm building a MySQL movie posters/fan art database driven by a PHP script. I
I am building a GUI for image processing in PyQt. One task that I
I am building up a database of movies. Each movie will have fields genre,
I'm building a site with django that lets users move content around between a

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.