Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何对关系中的表使用Group by?_C#_Sql_Linq_Entity Framework_Ado.net - Fatal编程技术网

C# 如何对关系中的表使用Group by?

C# 如何对关系中的表使用Group by?,c#,sql,linq,entity-framework,ado.net,C#,Sql,Linq,Entity Framework,Ado.net,我有两张桌子叫PatientMaster和DoctorMaster。他们之间的关系是多对一的。现在我试着写一个简单的条件,像这样,我想我写的LINQ是错误的 partial void PrintDocLetter1_CanExecute(ref bool result) { if (this.PatientsMasterItem.DoctorsMasterItem .GroupBy(i => i.DoctorsName)

我有两张桌子叫PatientMaster和DoctorMaster。他们之间的关系是多对一的。现在我试着写一个简单的条件,像这样,我想我写的LINQ是错误的

partial void PrintDocLetter1_CanExecute(ref bool result)
{
  if (this.PatientsMasterItem.DoctorsMasterItem
                             .GroupBy(i => i.DoctorsName)
                             .Any(l => l.Count() > 1))
  {
    result = false;
  }
}

如果不同的病人有相同的医生,我怎么能这样做呢?更大的情况是,只有当医生有一名患者时,我才能发送信函1;如果医生有超过1名患者,我可以发送信函2,其中信函1发送给其中一名患者

我理解你的问题,你想要这样的东西吗

var Doctor = PatientsMasterItem.DoctorsMasterItem;

var PatientList = Doctor.PatientMasterItems;

if(PatientList.Count() > 1)
{

}
else
{

}