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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:23:50+00:00 2026-06-11T14:23:50+00:00

I did not find the answer so i ask the question… Sorry to bother.

  • 0

I did not find the answer so i ask the question… Sorry to bother.

I use code first with an Article class looking like

public class Article
{
    ...
    public virtual ICollection<Photos> Images { get; set; }
    ...
}
public class Photo
{
   ...
   public string Location {get;set;}  //can be home, work or anything
   ...
}

Now, in the HomeController, i get all articles and do

if(articles.Any())
{
      ViewBag.Articles = articles;
}

And then, in the view

foreach(var article in ViewBag.Articles)
{
     ... Do things working great here but...
}

All of that works great. What I want to do is getting ONE Image with location==”home” (for example) from the ICollection for each article. Trying to do that i get different errors in french who says things like i “can not do a request of type dynamic on an other dynamic”, “a datareader is open yet” or “dbContext is closed”.

Thank you for any help.

  • 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-11T14:23:51+00:00Added an answer on June 11, 2026 at 2:23 pm

    I think ViewBag.Articles in the view did not contain Photo entities. When you tried to access Photos, the context was closed and caused an error.

    My suggestion would be:

    Call Include in your controller to early-load Photo entities.

    http://msdn.microsoft.com/en-us/library/bb738708.aspx

    Then, call ToList when you assign Articles:

    ViewBag.Articles = articles.ToList();

    Besides the point, it is good practice to use ViewModel, instead of putting data objects into ViewBag. Good luck.

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

Sidebar

Related Questions

I did not find an answer to this question. I have a VOIP application.
I did search the forum and did not find a similar question. I'm looking
I searched the site but did not find the answer I was looking for
Quick and simple question I did not find an answer for: How does TFS
I have Googled merge+cell+Javascript but did not find any suitable code to implement merge
So I've been looking for a good solution everywhere but did not find anything
Is there any minimum compute capability to use CUDA-OpenGL interoperability? I did not find
I have been thru a few questions but did not find an answer. I
Although the question title is duplicate of many discussions, I did not find a
I read and did not find the answer. I want to read a log

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.