Skip to content
Advertisement

SELECT the patients that have similar disease name EF core 3.1

I have the following tables

  1. Patients

      ID   PatientName   PatientIDNumber  
     ---- ------------- ----------------- 
       1   Jo                  411420607  
       2   Mark                206047758  
    

  1. Records

      ID    DiseaseName    PatinetID  
     ---- --------------- ----------- 
       1   Liver Disease           1  
       2   Heart Disease           1  
       3   Liver Disease           2  
       4   Heart Disease           2  
    

Each patient has many records


  • Patient Data model class

  • Record data model class


I want to create an API that takes a specific patient id as a parameter to get a list of other patients with similar diseases

  • Patient report API result (DTO)


Note: *Similar diseases mean that the two patients have in common 2 or more disease

How to List patients with similar diseases in EF core 3.1?

Advertisement

Answer

This is the bare bones of what you need, without relying on your disease names being in the same order.

If you need additional info like PatientName, you can just add them in by wrapping the select below in a cte and then join onto the Patient data:

As a fiddle.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement