LINQ离开了连接数据集和分组依据

时间:2014-01-09 20:30:31

标签: c# linq lambda outer-join

我的数据看起来像这样

  1. EOC - 案件ID,入院,出院
  2. PrinDiag - 每个EOC一个
  3. OtherDiag - 每个EOC 0,1或多个

     var results = from dtE in ds.Tables["EOC"].AsEnumerable()
           from dtPD in ds.Tables["PrinDiag"].AsEnumerable()
           .Where(t => dtE.Field<string>("case_id") ==  t.Field<string>("case_id") )
           .DefaultIfEmpty()
           .GroupBy(t => t.Field<string>("case_id"))
           from dtOD in ds.Tables["OtherDiag"].AsEnumerable()
           .Where(t => dtE.Field<string>("case_id") == t.Field<string>("case_id"))                                                 
           .DefaultIfEmpty()
           .GroupBy(t => t.Field<string>("case_id")).DefaultIfEmpty()
         select new { dtE, dtPD, dtOD };
    
  4. 我需要从这些数据创建XML。

    <eocdate>
    <EOC>test</EOC>
    <admission>22/06/2013</admission>
    <patient>
      <facility_patient_id>12345</facility_patient_id>
      <first_name>Matthu</first_name>
      <last_name>MOmmy</last_name>
    </patient>
    <assessment>
      <newborn_weight />
    </assessment>
    <principal_diagnosis>
      <principal_diagnosis_code>123   </principal_diagnosis_code>
      <principal_diagnosis_status>0</principal_diagnosis_status>
    </principal_diagnosis>
    <other_diagnosis>
      <other_diagnosis_code>435   </other_diagnosis_code>
      <other_diagnosis_status>0</other_diagnosis_status>
    </other_diagnosis>
    <other_diagnosis>
      <other_diagnosis_code>345   </other_diagnosis_code>
      <other_diagnosis_status>0</other_diagnosis_status>
    </other_diagnosis>
    <other_diagnosis>
      <other_diagnosis_code>1231  </other_diagnosis_code>
      <other_diagnosis_status>0</other_diagnosis_status>
    </other_diagnosis>
    </eocdate>
    

    我收到“值不能为空。\ r \ nParameter name:row”

    请帮忙。

    谢谢,

0 个答案:

没有答案