我有一个LINQ查询,它应该返回单个结果或不返回结果。我调用Single()是为了得到如下结果: where SomeCondition(x)当我的查询只有一个结果时,这是可以的,但是如果没有结果,则抛出一个带有消息序列的System.InvalidOperationException,其中不包含任何元素。
下面的代码如果在mongodb数据库中找到一个完全匹配的内容就会返回结果,但是当在数据库中找不到匹配的记录时,下面的代码会抛出"object reference not set to an instance“。 IMongoCollection<Retailers> retailerList = db.GetCollection<Retailers>(retailerinfoCollect
[Route("customers/show/{id}")]{
var customer = GetCustomers().SingleOrDefault参数字典包含“MyApp.Controllers.CustomersController”中非空类型'System.Int32‘的参数'id’的空项,用于方法'System.Web.Mvc.ActionResult可选参数必须是引用</e