4

如何让 linq pad 运行我的左连接,如下所示?

var query = 
            from s in db.CDBLogsHeaders
                    .OrderByDescending(g => g.LogDateTime)
                    from sc in db.StyleColors
                        .Where(stylecolor => stylecolor.id == (int?)s.StyleColorID)
                        .DefaultIfEmpty()
                    from c in db.StyleHeaders
                        .Where(styleHeader => styleHeader.id == (int?)s.StyleHeaderID)
                        .DefaultIfEmpty()
        select new 
        {
            CDBLogsHeaderId = s.Id,
            Merchandiser = c.Merchandiser,
            Material = s.Material,
            Season = s.Season,
            LogsHeaderLogType = s.LogType,
            PushFromTo = s.PushFromTo,
            LinePlan = s.LinePlan,
            QuikRefNumber = s.QuikRefNumber,
            PLMOrigin = s.PLM_Origin,
            SeasonOriginal = c.SeasonOriginal,
            SeasonCurrent = c.SeasonCurrent,
            StyleHeaderId = c.Id,
            StyleCode = c.StyleCode,
            StyleColorsColorCode = sc.ColorCode
        };

    query.Dump();

linq pad 创建的 sql 在 Management Studio 中完美运行,但 linq-pad 不显示任何行并给出此错误

InvalidOperationException:无法将 null 值分配给 System.Int32 类型的成员,该类型是不可为 null 的值类型。

我怎样才能让 linqpad 工作,这样我就可以玩它了?

4

1 回答 1

3

在您的匿名类型中,确保您的整数返回整数。

改变

StyleHeaderId = c.Id,

StyleHeaderId = (c.Id == null ? 0 : c.Id),
于 2012-05-03T17:23:08.617 回答