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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:27:08+00:00 2026-05-31T13:27:08+00:00

i have the following lambda expression in MVC application.i want to group data. var

  • 0

i have the following lambda expression in MVC application.i want to group data.

 var toprating=  _db.Movie.SelectMany(m => m.Rating.Select(r=> new 

            {

           movieID=r.MovieID,
           MovieTitle= m.Title
            })).GroupBy(m=>m.movieID).ToList();

      ViewBag.TopMovie = toprating;
        }

i want to pass this to my view.
i try writing the following in my view

 IEnumerable<Movie> TopMovies = ViewBag.TopMovie;

but got this error

Cannot implicitly convert type 'object' to 'System.Collections.Generic.IEnumerable<Movie>'. An explicit conversion exists (are you missing a cast?)

any help will be appriciated.

  • 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-31T13:27:08+00:00Added an answer on May 31, 2026 at 1:27 pm

    The type of the collection that you are passing in isn’t an IEnumerable<Movie>. Notice you are using an anonymous type, and then you’re also using GroupBy. The resulting type is complex.

    Your query is also meaningless because you’re accessing Rating but not using it, so you probably end up with multiple copies of the same movie, and with all the rating information discarded. For the moment I’ll assume you actually want the ratings included.

    So you could use the following query, for example:

    ViewBag.Ratings = _db.Movie.SelectMany(m => m.Rating.Select(r => new 
    {
        Movie = m,
        Rating = r
    })).GroupBy(m => m.Movie, m => m.Rating).ToList();
    

    Now the type of the above query is List<IGrouping<Movie, Rating>>, so you can use that in your view:

    List<IGrouping<Movie, Rating>> ratings = ViewBag.Ratings;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following lambda expression: IEnumerable<Order> query = _ordersRepository.GetAllByFilter( o => o.OrderStatus.OrderByDescending(os =>
Supposing I have the following LambdaExpression: var itemParam = Expression.Parameter(typeof(Thing), thing); var someValue =
I have the following method I can pass in a lambda expression to filter
I have the following expression var q = from c in D1 join dp
I have the following lambda function: f = lambda x: x == None and
If I have the following named_scope named_scope :scope_by_user_id, lambda {|user_id| {:conditions => [comments.user_id =
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
i have data in following format: colA colB 2010 10 2010 20 2010 30
I am looking at better way of writing following code using linq/lambda expression.. I
I have the following code, which shows a squiggly red line under the lambda

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.