我对Linq比较陌生,现在我遇到了以下问题。 我有以下功能:在LINQ to SQL中与GROUP BY左连接
public Dictionary<DateTime, List<PloegenRooster_Uitzonderingen>> GetPloegenRoosterUitzonderingen(char ploeg, DateTime fromDate, DateTime toDate)
{
return (
from item in this.GetTable<PloegenRooster_Uitzonderingen>()
join itemType in PloegenRooster_Uitzondering_Types on item.UitzonderingTypeId equals itemType.Id
group item by item.Datum
).ToDictionary(d => d.Key, d => d.ToList());
}
这很好用。但是,现在我正在试图将其变为左连接。 我结束了以下内容:
public Dictionary<DateTime, List<PloegenRooster_Uitzonderingen>> GetPloegenRoosterUitzonderingen(char ploeg, DateTime fromDate, DateTime toDate)
{
return (
from item in this.GetTable<PloegenRooster_Uitzonderingen>()
join itemType in PloegenRooster_Uitzondering_Types on item.UitzonderingTypeId equals itemType.Id into itemTypeJ
from itemTypeS in itemTypeJ.DefaultIfEmpty()
group item by item.Datum
).ToDictionary(d => d.Key, d => d.ToList());
}
但现在我收到以下异常:
The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
谢谢。这对我来说有点愚蠢。在我更改数据库列以允许空值后,我忘记更新DataContext。 – sroes