2013-05-29 34 views
0

嘗試連接兩個疾病列表時出現此錯誤GetDiseaseBySymptoms方法DiseaseSymptomMapping &症狀。可以通過更好的理解來提示GetDiseaseBySymptoms的代碼出了什麼問題。連接子句中表達式之一的類型不正確。加入調用中的類型推斷失敗

注意:不要擔心GetDiseaseBySymptoms方法的返回類型,一旦解決此問題,將在以後處理。

class Program 
    { 
     static void Main(string[] args) 
     { 
      Disease malaria = new Disease { ID = 1, Name = "Malaria" }; 
      Disease Cholera = new Disease { ID = 1, Name = "Cholera" }; 

      Symptom Fever = new Symptom { ID = 1, Name = "Fever" }; 
      Symptom Cough = new Symptom { ID = 2, Name = "Cough" }; 
      Symptom Shevering = new Symptom { ID = 3, Name = "Shevering" }; 

      List<DiseaseSymptomMapping> DiseaseDetails = new List<DiseaseSymptomMapping> { 
       new DiseaseSymptomMapping{ ID=1,disease=malaria,symptom=Fever}, 
       new DiseaseSymptomMapping{ ID=2,disease=malaria,symptom=Shevering}, 
       new DiseaseSymptomMapping{ ID=3,disease=Cholera,symptom=Fever}, 
       new DiseaseSymptomMapping{ ID=4,disease=Cholera,symptom=Cough} 
      }; 

      List<Symptom> symptoms = new List<Symptom> { Fever, Fever,Shevering }; 

      List<Disease> diseases = GetDiseaseBySymptoms(symptoms, DiseaseDetails); 

      foreach (Disease disease in diseases) 
      { 
       Console.WriteLine("Disease Name :{0}", disease.Name); 
      } 

      Console.ReadLine(); 
     } 

     class Disease 
     { 
      public int ID { get; set; } 
      public string Name { get; set; } 
     } 

     class Symptom 
     { 
      public int ID { get; set; } 
      public string Name { get; set; } 

     } 

     class DiseaseSymptomMapping 
     { 
      public int ID { get; set; } 
      public Disease disease { get; set; } 
      public Symptom symptom { get; set; } 

     } 



     static List<Disease> GetDiseaseBySymptoms(List<Symptom> symptoms,List<DiseaseSymptomMapping> DiseaseDetails) 
     { 
       var querytmp = from diseasedetails in DiseaseDetails 
         join symp in symptoms on diseasedetails.symptom equals symp in symptomsgrp 
         select new 
         { 
         DiseaseName= diseasedetails.Name, 
         Symptoms=symptomsgrp 
         }; 

       foreach (var v in querytmp) 
     { 
      Console.WriteLine("{0}", v.DiseaseName); 
     } 
          return new List<Disease>(); 
     } 


    } 

回答

1

變化in symptomsgrp變爲into symptomsgrp。你會得到改變

DiseaseName = diseasedetails.Name 

DiseaseName = diseasedetails.disease.Name 
擺脫錯誤的
相關問題