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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:44:00+00:00 2026-06-15T11:44:00+00:00

I have two tables. One table is called Occurrence that contains the following: OccurrenceID

  • 0

I have two tables. One table is called Occurrence that contains the following:

OccurrenceID | EmployeeID | OccurrenceDate | Points | Comment
-------------------------------------------------------------
1            |1           |2012-01-01      |5       |yada    
2            |1           |2012-02-01      |3       |blah    
3            |2           |2012-03-01      |2       |yada

The other table is called Employee and contains the following:

EmployeeID | EmployeeName
-------------------------
 1         |Jack
 2         |Jill

I am trying to group these two tables together and end up with a single line for each employee that will show the total points in a view in my MVC 4 project. So for the above example my output should be:

Name    | Points
----------------
Jack    |8
Jill    |2

Here is the LINQ query that I’ve tried in my Controller:

        var groupedOccurrences = from o in db.Occurrences.Include(o => o.Employee)
                                 where o.OccurrenceDate >= beginDate
                                    && o.OccurrenceDate <= endDate
                                 group o by new {o.EmployeeID, o.Points} into g
                                 select new {
                                     Name = g.Key.EmployeeID,
                                     Total = g.Sum(o => o.Points)
                                 };

        return View(groupedOccurrences);

And here is my View:

@model IEnumerable<PtoTracker.Occurrence>

<table>
    <tr>
        <th>
            Employee
        </th>
        <th>
            Total Pts.
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Employee.EmployeeName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Points)
        </td>
    </tr>
}
</table>

When I navigate to this view I get this error:

The model item passed into the dictionary is of type ‘System.Data.Entity.Infrastructure.DbQuery1[<>f__AnonymousType32[System.Int32,System.Int32]]’, but this dictionary requires a model item of type ‘System.Collections.Generic.IEnumerable`1[PtoTracker.Occurrence]’.

Can someone help me understand what I should be doing differently?

  • 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-15T11:44:01+00:00Added an answer on June 15, 2026 at 11:44 am

    You need to new up instances of your view expected class

    var groupedOccurrences = 
       (from o in db.Occurrences.Include(o => o.Employee)
        where o.OccurrenceDate >= beginDate && o.OccurrenceDate <= endDate
        group o by new {o.EmployeeID, o.Points} into g
        select new { Name = g.Key.EmployeeID, Total = g.Sum(o => o.Points)}
       ).AsEnumerable();
    
    
    var model = groupedOccurrences.Select(item => new PtoTracker.Occurrence { 
                             Name = item.Name,
                             Total = item.Total });
    

    your view is expecting IEnumerable of PtoTracker.Occurrence but you are sending it an IQuerable of anonymes type instead.

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

Sidebar

Related Questions

I have two tables. One table contains words. Other table contains points. table words:
I have two tables having 1 to 1 relationship. One table called Person and
I have two tables that I'm querying from. In one table, there are fields
I have two database tables. One table stores data for a commitment that a
I have two tables, one called episodes, and one called score. The episode table
I have two tables, one table is called queuelist and the other is call
I have two tables, one called Events and one called Documents. Each table has
I have two tables, one is called video_2, one is called vlan. Table vlan
I have two tables one called fs_note the other called dumy_fs_note I created after
i have two tables one is called addons and holds information about different addons,

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.