C# 在LINQ到SQL中与GROUP BY左连接

C# 在LINQ到SQL中与GROUP BY左连接,c#,linq-to-sql,C#,Linq To Sql,我是Linq的新手,现在我有以下问题。 我有以下功能: public Dictionary<DateTime, List<PloegenRooster_Uitzonderingen>> GetPloegenRoosterUitzonderingen(char ploeg, DateTime fromDate, DateTime toDate) { return ( from item in this.GetTable

我是Linq的新手,现在我有以下问题。 我有以下功能:

    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());
    }
在与第一个示例类似的(内部)联接中,仅选择与另一个表中的行匹配的行

在左侧连接中,选择表A中的所有行。如果第二个表中没有适合联接的行,则第二个表的列将填充空值。创建的对象具有Integer属性。整数属性不包含空值


您必须将Integer属性更改为可为Null的数据类型,或使Integer属性可为Null。

在第一次尝试中,存在一个equi联接,联接中的两个表都有一个结果。但是,当使用左联接时,其中一个表会产生空值,因为两个表之间没有匹配键

正如@TheJoelaut所提到的,通过添加select子句,使您的属性可为null,或者为null赋值零或有效整数数据:


选择itemTypeS==null?(Int32)0.00:itemTypeS.property

谢谢。我真是太蠢了。在将数据库列更改为允许空值后,我忘记了更新DataContext。
    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.