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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:20:35+00:00 2026-05-23T03:20:35+00:00

I have two tables having 1 to 1 relationship. One table called Person and

  • 0

I have two tables having 1 to 1 relationship. One table called Person and second is PersonDetails. PesonId is in PersonDetails table as FK.

I can query individual tables like

public static Person GetPersonById(int personId)
{
    using (var context = new REntities())
    {
    return context.Person.Where(p => p.PersonId == personId).First();
    }
}

It is being used in consuming code like:

Person personInfo = PersonService.GetPersonById(personId);

and same with PersonDetail on its PK i.e. PersonDetailId

But when I have to fetch data from two tables then I am not understanding that what how would I do this and what would be the best way to return data to presentation layer.

Following would be the code to get Person and relate PersonDetails records:

from personData in context.person.Include("PersonDetail")
                                  where personData.PersonId == personId
                                  select personData;

What is personData here?
How can I iterate over it and get each item in client code?

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-05-23T03:20:36+00:00Added an answer on May 23, 2026 at 3:20 am

    When you get your Person object, you can include the PersonDetails object as well within the query like this…

    using (var context = new REntities())
    {
      return context.Person.Include("PersonDetail").Where(p => p.PersonId == personId).First();
    }
    

    Now on the presentation side, when you get the Person object, iterate through each item of person detail like this…

    from p in personInfo.PersonDetails
    select p; // here p is the person detail object
    

    Hope it helps.

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

Sidebar

Related Questions

I have two tables related: DataEntered and Model DataEntered -currentModel Model One DataEntered can
I have two tables.One table contain the values +---------+ Users ---------+ A B C
From the regular aspnet_Users table I have created two sub-tables with one to one
I have two tables with a many to one relationship which represent lots and
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have two tables in my database, called ratings and movies . Ratings: |
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
Could someone help me with building the following query. I have a table called

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.