获取此行的异常:
public bool isEngageOn()
{
line 149 -> return chatUserRepository.Table.Where(c => c.TrackingOn).Any();
}
TrackingOn
是布尔类型。
.Any()假设“确定天气一个序列包含任何元素”,那么为什么 Elmah 捕获的异常“System.InvalidOperationException Sequence contains no elements”?
错误:
System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at System.Linq.Queryable.Any[TSource](IQueryable`1 source)
at sf2015.Models.DomainModels.Services.ChatServices.isEngageOn() in C:\....\ChatServices.cs:line 149
ps:无法重现错误,但有时会显示在Elmah错误日志中。
以下是存储库的一些代码
public virtual IQueryable<T> Table
{
get
{
return this.Entities;
}
}
private DbSet<T> Entities
{
get
{
if (_entities == null)
_entities = Context.Set<T>();
return _entities;
}
}