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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:30:56+00:00 2026-05-27T15:30:56+00:00

I am using the Entity Framework to access my database and I just figured

  • 0

I am using the Entity Framework to access my database and I just figured out that mapping stored procedures to methods using entity is a bit too complex and probably not well suited to do what I want exacltly. I am new to LINQ and I am wondering if I sould be better off just with ADO.NET. Here is the SQL code I need to translate:

SELECT p.Player_id, p.Name, p.Position, SUM(s.Goals) AS goalsb, SUM(s.Assists) AS assistsb, SUM(s.Points) AS pointsb
FROM Dim_Player AS p INNER JOIN Fact_Statistics AS s ON s.Player_id = p.Player_id
GROUP BY p.Player_id, p.Name, p.Position
ORDER BY pointsb DESC, goalsb DESC

With the Entities mapping for stored procedures, I had this code written:

HockeyStatsEntities db = new HockeyStatsEntities();

public ActionResult Index()
{
    ViewBag.Message = "League leaders";
    {
        return View(db.ListLeagueLeaders());
    }
}

public ActionResult About()
{
    return View();
}

private ICollection<ListLeagueLeaders_Result> ListLeagueLeaders()
{
    ICollection<ListLeagueLeaders_Result> leagueLeadersCollection = null;

    using (HockeyStatsEntities context = new HockeyStatsEntities())
    {
        foreach (ListLeagueLeaders_Result leagueLeader in
                  context.ListLeagueLeaders())
        {
            leagueLeadersCollection.Add(leagueLeader);
        }
    }
    return leagueLeadersCollection;
}

Here is the error I am getting:

The model item passed into the dictionary is of type
‘System.Data.Objects.ObjectResult`1[NHLStats2.Models.ListLeagueLeaders_Result]’,
but this dictionary requires a model item of type
‘NHLStats2.Models.ListLeagueLeaders_Result’.

But I realize that this is a bit of a pain in the ?&*@… How could I re-arrange this using a different, more effective method? Thanks for your help, it’s really appreciated.

  • 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-27T15:30:57+00:00Added an answer on May 27, 2026 at 3:30 pm

    Finally opting for using a stored procedure, this compiles and works:

    Model1.tt.Context.cs (autogenerated)

    public DbSet<Dim_Date> Dim_Date { get; set; }
        public DbSet<Dim_Player> Dim_Player { get; set; }
        public DbSet<Dim_Team> Dim_Team { get; set; }
        public DbSet<Fact_Statistics> Fact_Statistics { get; set; }
        public DbSet<Dim_Game> Dim_Game { get; set; }
    
        public virtual ObjectResult<ListLeagueLeaders_Result> ListLeagueLeaders()
        {
            ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(ListLeagueLeaders_Result).Assembly);
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ListLeagueLeaders_Result>("ListLeagueLeaders");
        }
    

    View

    @model System.Data.Objects.ObjectResult<NHLStats2.Models.ListLeagueLeaders_Result>
    
    @{
        ViewBag.Title = "Index";
    }
    
    [...]
    

    Problem was with the strongly typed view type not matching the System.Data.Objects.ObjectResult type. Was: @model NHLStats2.Models.ListLeagueLeaders_Result, changed to: @model System.Data.Objects.ObjectResult<NHLStats2.Models.ListLeagueLeaders_Result> Cheers!

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

Sidebar

Related Questions

I'm using Entity Framework to access my MySQL database. The model was generated using
I am mapping some pre-existing Business Objects to our database using Entity Framework. These
We are using entity framework 4 to access our database. Every table has got
I am using Entity Framework 4.1 for database access and would like to Unit
I'm using Entity Framework for creation of my Data Access Layer and I want
Last year I developed a data access service for our project using Entity Framework
I'm getting into using the Repository Pattern for data access with the Entity Framework
I'm using Entity Framework in my project, and I have the problem that, once
We are using .Net Entity Framework to do our database related work. Our database
I am successfully creating database (SQL Ce) using Entity Framework Code First approach (C#-WPF).

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.