[英]LINQ DefaultIfEmpty issue on object with non-nullable value type property
from records in DBContext.Table1
join history in DBContext.Table2 into recordhistory
from records in recordhistory.DefaultIfEmpty()
select (n => n);
The error I got is "The null value cannot be assigned to a member with type System.Guid which is a non-nullable value type." 我得到的错误是“不能将空值分配给类型为System.Guid的成员,这是非空值类型。”
Can someone advise me on this? 有人可以建议我吗? Thank you very much.
非常感谢你。
Assuming you have an ID property, following should work as inner join: 假设您具有ID属性,则以下内容应作为内部联接工作:
var result = DBContext.Table1
.Join(DBContext.Table2, t1 => t1.ID, t2 => t2.ID, (t1, t2) => t1);
I guess, the query, you provided, shoulg give an error, saying that on
statement should be specified. 我猜想,您提供的查询应该给出一个错误,说应该指定
on
语句。 So, I guess it should look somewhat like this: 因此,我想它应该看起来像这样:
from records in DBContext.Table1
join history in DBContext.Table2 on records.ID equals history.ID into temp
from recordhistory in temp.DefaultIfEmpty()
select new { Record = records, History = recordhistory };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.