如何在LinqPad中执行左连接

4
如何让 LinqPad 执行下面所示的左连接?
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();

在 Management Studio 中,Linq Pad 创建的 SQL 运行得非常完美,但 Linq Pad 却没有显示任何行,并出现以下错误:
“InvalidOperationException: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.”
我该如何让 Linq Pad 正常工作以便我可以使用它?

http://meta.stackexchange.com/a/128558/102937 - Robert Harvey
1个回答

3

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

更改为:

StyleHeaderId = c.Id,

To

StyleHeaderId = (c.Id == null ? 0 : c.Id),

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接