0
我有以下的Linq查询:LINQ查询帮助 - 检测NULL值
(from container in Container
join containerType in ContainerType on container.ContainerType equals containerType
where containerType.ContainerTypeID == someIDValue
select container).Max (row => Convert.ToInt64(row.SerialNumber))
该查询的伟大工程的,只要至少一个集装箱排符合标准。如果没有行符合条件的,我得到以下错误:
The null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type
有没有办法让我能改写这一点,如果没有行满足任意值被返回的查询,说-1?
你可能有在第一个查询的末尾添加一个.SingleOrDefault(),如下所示:select container).SingleOrDefault(); – Tahbaza 2010-06-30 16:06:39
查询不会为空,它将是空的。 – Toby 2010-06-30 16:09:55
托比你是对的。对不起,大家 – frabiacca 2010-06-30 16:11:50