尝试加入两个 DiseaseSymptomMapping 和 Symptom 类型列表时,在下面的 GetDiseaseBySymptoms 方法中出现此错误。任何有助于更好地理解的帮助都可以建议 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>();
}
}