当IQueryable不返回任何记录时,ToList()会引发异常 [英] When IQueryable returns no record ToList() throws an exception
本文介绍了当IQueryable不返回任何记录时,ToList()会引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
dataContext.Geo_Countries.Where(c => c.Name.Contains(searchKey))。ToList();
dataContext.Geo_Countries.Where(c => c.Name.Contains(searchKey)).ToList();
当IQueryable不返回记录时我得到一个值null异常。
when the IQueryable returns no records I get a value null exception.
解决方案是什么?
推荐答案
I怀疑没有匹配项时您没有遇到问题-我怀疑您的数据库中有一行没有 Name
值的问题。要么是,要么您正在做其他未向我们展示的事情。堆栈跟踪是什么样的?
I suspect you don't get the problem when there are no matches - I suspect you get it when there's a row in your database with no Name
value. Either that, or you're doing something else which you haven't shown us. What does the stack trace look like?
这篇关于当IQueryable不返回任何记录时,ToList()会引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文