LINQ 运算符'=='不能应用于类型 'method group' 和 'int' 的操作数



我有如下内容:

    var lst = db.usp_GetLst(ID,Name, Type);
    if (lst.Count == 0)
    {
    }

我在lst下面躺了一会儿。计数 == 0,它说:

运算符"=="不能应用于类型为"方法组"和"int"的操作数

Enumerable.Count是一个扩展方法,而不是一个属性。这意味着usp_GetLst可能会返回IEnumerable<T>(或一些等效物),而不是您期望的IList<T>ICollection<T>的导数。

// Notice we use lst.Count() instead of lst.Count
if (lst.Count() == 0)
{
}
// However lst.Count() may walk the entire enumeration, depending on its
// implementation. Instead favor Any() when testing for the presence
// or absence of members in some enumeration.
if (!lst.Any())
{
}

有时缺少在视图顶部添加模型,那时候你会得到同样的错误例如。- @model列表<测试.管理员.模型>

最新更新