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

  • Home
  • SEARCH
  • 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 6349615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:39:05+00:00 2026-05-24T21:39:05+00:00

I have a project using Entity Framework code first. For various reasons one of

  • 0

I have a project using Entity Framework code first.

For various reasons one of the linq queries just doesnt perform well and I want to replace it with a stored procedure call.

The following code works fine for calling a stored procedure and converting the result into a List.

IEnumerable<Activity> activities =
    ((IObjectContextAdapter)MyContext)
       .ObjectContext.ExecuteStoreQuery<Activity>("GetActivities").ToList();

However I also want some includes on the activity model to load one of the child collections on that object. For example Activity has a Virtual List collection. Is there a way I can in my stored procedure also return the Tags for each activity.

If I do the following does not work

SELECT
   Activities.ID,
   Activities.Name,
   Tags.ID,
   Tags.Name
FROM
   Activities
   LEFT JOIN ActivityTags ON ActivityTags.ActivityID = Activities.ID
   LEFT JOIN Tags ON Tags.ID = ActivityTags.TagID

It errors in the C# saying its not a valid activity. If I remove the Tags bit from the stored procedure so it just selects from the Activities table it works fine.

I’m not sure if what I’m asking is possible with a stored procedure using the entity framework or not. If not I may have to resort to using the SqlCommand and building the model from my result set myself.

  • 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-24T21:39:06+00:00Added an answer on May 24, 2026 at 9:39 pm

    It is not possible. Automatic entity population works only for flat objects = you can populate Activity but not its relation. You must use standard ADO.NET if you want to load relations as well but in such case it would be better to modify your stored procedure to return separate result set for each table to reduce amount of transferred data.

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

Sidebar

Related Questions

I have developed a project using MVC3 and Code first Entity Framework 4.0 as
I have been using Entity Framework CTP with Code-First as in this tutorial by
I'm using Entity Framework 4 Code First in my .net MVC 2.0 project and
Using the Entity Framework 4. I have created a Code First database in the
I am using Entity Frameworks Code First. I have one entity that I need
I'm wondering if using VS.Net 2010, I can have Entity Framework 3.5 code running
my current project is based on Entity Framwork code-first. I have three types: Task,
I'm working on my 1st project using MS Unity IoC framework. If I have
I have a project with a formidable data access layer using LinqtoSQL for just
I'm using Entity Framework 4 in my project. The Framework has created its own

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.