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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:14:56+00:00 2026-06-04T14:14:56+00:00

How to select all records from one table that have corespondent keys with other,

  • 0

How to select all records from one table that have corespondent keys with other, using joining table. I have table dbo.Patients and dbo.Hospitals and dbo.PatientHospitals which has Primary keys from both tables. I need all recods from dbo.Patients that are in dbo.Hospitals, that is that are in joining table dbo.PatientHospitals, something like:

var currentHospital = db.Hospitals.Single(x => x.User_Id == UserID);

var model = db.Patients.Include("Hospitals")
              .Select(x => x.Hospitals == currentHospital);  
  • 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-04T14:14:57+00:00Added an answer on June 4, 2026 at 2:14 pm

    In code first, you do not need additional table for simple many-to-many relationship. You could define your entities like this

    public class Patient
    {
        ...    
        public virtual ICollection<Hospital> Hospitals { get; set; }    
        ...
    }
    
    public class Hospital
    {
        ...    
        public virtual ICollection<Patient> Patients { get; set; }    
        ...
    }
    

    And then you could just write currentHospital.Patients

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

Sidebar

Related Questions

I am fetching all records from a db table into a page using; SELECT
I have a One to Many relationship. I want to select all records from
I have a large table (~10 million records) that contains several keys into other,
I'd like to select all rows from one table which match one or more
I have a procedure to loop through records from one table with a cursor
I have a Pl/SQL query that pull all records from the 3 tables. That
I have two tables. I try to select some records from one of them.
I have an array populated with records from one table and want to count
How would I write a SQLite query to select all records from a specific
Table A, columns OrderId, OrderTimeStamp (datetime). I want to SELECT all records for any

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.