/// <summary>
/// Find all of the Areas that are Parents without children Areas.
/// </summary>
/// <returns>IQueryable object full of Areas.</returns>
public IQueryable FindParentAreas()
{
return db.Areas.SelectMany(x => x.ParentAreaID == null);
}
我想返回作为父区域的区域对象的集合,这意味着它们在 ParentAreaID 字段(在我的数据库中)中具有空值。
看来我不能只将它与 null 进行比较,因为 C# 中的 null 可能在 Microsoft SQL Server 中表示其他含义。
有什么指导吗?我应该使用 SelectMany 吗?
最佳答案
Projects each element of a sequence to an IEnumerable<T> and flattens the resulting sequences into one sequence.
Filters a sequence of values based on a predicate.
我认为您正在寻找Where
:
public IQueryable<Area> FindParentAreas()
{
return db.Areas.Where(x => x.ParentAreaID == null);
}
关于c# - 无法从用法中推断出方法的类型参数。尝试指定类型参数 ex - 错误。任何指导?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3071235/