2011-08-11 8 views
1

私はlinq-to-sqlを使用して、dbにある処方のテーブルと患者の呼び出しPatientListのリストとの間の結合を作成しています。複数の条件に参加

テーブルとリストに、過去の処方箋ステータスで患者リストをフィルタリングするために結合を作成するために使用するPatientIDというintが含まれているとします。

私はwhere句に挑戦しています。処方箋のステータスは1から6までです。患者ごとに多くの異なる処方があります。私は特定の状態で処方箋を受けている患者をPatientListから削除することを検討しています。私は、ステータス5の処方箋を少なくとも1つ持っているが、ステータス4と6のステータスを持っていないすべての患者を欲しい。したがって、例えば、処方a)3,1,5,3,2またはb)3,5,5,1,3は良好であるが、c)2,1,5,6,2またはd)1,3、

var TheOutput = from patients in PatientList 
       join prescrip in MyDataContext.Prescriptions on 
       patients.PatientID equals prescrip.PatientID 
       where prescrip.PrescripStatus == 5 && 

私は理由こだわっている:最初のものは6が含まれている2つ目は、5

を持っていません。これは、私がこれまで持っているものであるため、4,2,1は大丈夫ではありません私がそういうことをしたら、私は大文字小文字のc)大丈夫になるでしょう。

このクエリの問題に関するご意見ありがとうございます。

答えて

0

だから、あなたは5を持っていたすべての患者をしたいが、私はわからないではない4または6

が参加する必要があります。あなたはただ患者に戻ってほしいですよね?

var TheOutput = (from patients in PatientList 
       where (from prescrips in MyDataContext.Prescriptions 
         where prescrips.PatientID = patients.PatientID 
          && prescrips.PrescripStatus == 5 
         select prescrips).Any() 
        &&!(from prescrips in MyDataContext.Prescriptions 
         where prescrips.PatientID = patients.PatientID 
          && (prescrips.PrescripStatus == 4 || prescrips.PrescripStatus == 6) 
         select prescrips).Any() 

       select patients); 
0

この

var TheOutput = from patients in PatientList     
       join prescrip in MyDataContext.Prescriptions on     
       patients.PatientID equals prescrip.PatientID 
       join patients2 in PatientList on 
       patients.PatientID equals patients2.PatientID 
       join prescrip2 in MyDataContext.Prescriptions on     
       patients2.PatientID equals prescrip2.PatientID 
       where (prescrip.PrescripStatus == 5 && (prescrip2.PrescripStatus != 4 && prescrip2.PrescripStatus != 6)) 
のようなものを試してください:

私はこのような何かをしようとするだろう