我對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