【发布时间】:2012-09-17 00:03:17
【问题描述】:
要求
- 我需要加入Table1和Table2
- 两个表之间的键是ID,它是System.Guid类型,是不可为空的值类型
- 如果 Table2.ID 为空,我需要从 Table1 中获取空记录。
我写的LINQ语法如下。
from records in DBContext.Table1
join history in DBContext.Table2 into recordhistory
from records in recordhistory.DefaultIfEmpty()
select (n => n);
我得到的错误是“无法将空值分配给 System.Guid 类型的成员,这是一个不可为空的值类型。”
有人可以给我建议吗?非常感谢。
【问题讨论】:
-
"如果 Table2.ID 为 null,我需要从 Table1 中获取 null 记录" 什么意思:可以有没有 ID 的历史记录吗?或者你的意思是没有历史记录的Table1记录,如果是这样,不要选择Table1记录?
标签: c# linq defaultifempty