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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:11:57+00:00 2026-06-11T16:11:57+00:00

There are times where I have to display the relationship between two entities. Question

  • 0

There are times where I have to display the relationship between two entities. Question is, should you retrieve the data all in one query (with a join statement)?

For example, I have the entity User and Picture. A picture is created by one user. If I wanted to display list of picture names, and who uploaded the certain picture.

Two approaches:

1) Using Entity Framework relationship, where Pictures is an entity, and it has a User property (the user that created it). The User is an entity too.

foreach(var picture : context.Pictures.all){
  picture.name
  picture.user.name
}

2) Combining Picture & User into one POCO object and return that to the controller.
Controller:

foreach(var pictureUser : dal.GetPictureUsers){
  pictureUser.PictureName
  pictureUser.UserName
}

GetPictureUsers()
{
  PictureUser pictureUserPoc = new PictureUsersql.Include("Picture").include("User").Select(sa=> new PictureUser {
                                                                              PictureName = sa.PictureName, 
                                                                              UserName = sa.UserName});
}

The latter one was suggested in order to increase performance. Personally I would have written it in the former way since you do not couple what you want in the View logic (having Picture and User relationship printed) in the data access layer.

I hope I have stated the question clearly.
Thanks!

  • 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-11T16:11:59+00:00Added an answer on June 11, 2026 at 4:11 pm
    @foreach (var profile in Model)
    {
      @Html.DisplayFor(model=>profile.PictureName);
      @Html.DisplayFor(model=>profile.User.Name);
    }
    

    The Model represents the Pictures; if you strongly type the view then you can use it.

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

Sidebar

Related Questions

I have a nettcpbinding wcf service.It called 100000+ times in one second so there
There have been many times on StackOverflow where a user asks a question like
Is there a way I can have an excel track the number of times
I have a class that refers to UiApplication.getUiApplication() multiple times, would there be any
Is it possible to have Android's numeric keypad display for an EditText (the one
i have two table with many to many relationship when i apply findbyall method
I work a lot with nested data structures, and many times I have to
I have a page that displays two objects and then the user picks one
i have two tables: Authority , Permission they have many to many relationship class
All, I have a need to display information on a MapView object. No problems

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.