Linq join子句中某个表达式的类型不正确。调用join时类型推断失败

Linq join子句中某个表达式的类型不正确。调用join时类型推断失败,linq,Linq,尝试联接两个类型为DiseaseSemplograpping&Symptom的列表时,在下面的GetDiseaseBySymptoms方法中获取此错误。有什么能帮助我们更好地理解GetDiseaseBySymptoms代码的错误吗 注意:不要担心GetDiseaseBySymptoms方法的返回类型,一旦这个问题得到解决,稍后会注意到这一点 class Program { static void Main(string[] args) {

尝试联接两个类型为DiseaseSemplograpping&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>();
        }


    }
类程序
{
静态void Main(字符串[]参数)
{
疾病疟疾=新疾病{ID=1,Name=“疟疾”};
疾病霍乱=新疾病{ID=1,Name=“Cholera”};
症状发烧=新症状{ID=1,Name=“发烧”};
症状咳嗽=新症状{ID=2,Name=“Cough”};
症状显示=新症状{ID=3,Name=“显示”};
List DiseaseDetails=新列表{
新疾病症状图{ID=1,疾病=疟疾,症状=发烧},
新疾病症状图{ID=2,疾病=疟疾,症状=暴露},
新疾病症状图{ID=3,疾病=霍乱,症状=发烧},
新疾病症状图{ID=4,疾病=霍乱,症状=咳嗽}
};
列表症状=新列表{发烧、发烧、发烧};
列出疾病=根据症状(症状、疾病详情)获取疾病;
foreach(疾病中的疾病)
{
WriteLine(“疾病名称:{0}”,Disease.Name);
}
Console.ReadLine();
}
类疾病
{
公共int ID{get;set;}
公共字符串名称{get;set;}
}
类症状
{
公共int ID{get;set;}
公共字符串名称{get;set;}
}
类病态映射
{
公共int ID{get;set;}
公共疾病{get;set;}
公共症状{get;set;}
}
静态列表GetDiseaseBySymptoms(列出症状,列出疾病详细信息)
{
var querytmp=来自diseasedetails中的diseasedetails
在疾病详情的症状中加入症状。症状等于症状GRP中的症状
选择新的
{
DiseaseName=diseasedetails.Name,
症状
};
foreach(querytmp中的变量v)
{
Console.WriteLine(“{0}”,v.DiseaseName);
}
返回新列表();
}
}

将症状GRP中的
更改为
为症状GRP
。你可以通过改变来消除错误

DiseaseName = diseasedetails.Name

DiseaseName = diseasedetails.disease.Name