我得到'Sequence contains no elements'with LINQ FirstOrDefault。序列不包含LINQ的元素FirstOrDefault
int? locationId = _ctx.m_locations.FirstOrDefault(
l => l.name.ToLower() == countyOrTown.ToLower()
).location_key;
我认为FirstOrDefault的整点是,如果在数据库中没有条目不会引发异常,只是返回null?
即便如此,当`null`返回时,您如何成功访问`location_key`? – 2011-02-16 16:08:45
什么是堆栈跟踪? – SLaks 2011-02-16 16:09:19