如何让 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 不显示任何行并给出此错误
无效操作异常:不能将空值分配给 类型为 System.Int32 的成员,该成员是不可为空的值类型。
如何让 linqpad 工作以便我可以使用它?
在您的匿名类型中,确保您的整数返回 int。
改变
StyleHeaderId = c.Id,
自
StyleHeaderId = (c.Id == null ? 0 : c.Id),