Reputation: 41208
/// <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);
}
I want to return a collection of Area objects that are parent Areas, meaning they have null values in the ParentAreaID field (in my database).
It seems I can't just compare it to null because null in C# maybe means something else in Microsoft SQL Server.
Any guidance? Should I even be using SelectMany?
Upvotes: 2
Views: 2707
Reputation: 1953
I think you want to use Where:
return db.Areas.Where(x => x.ParentAreaID == null)
Upvotes: 2
Reputation: 217361
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.
I think you're looking for Where
:
public IQueryable<Area> FindParentAreas()
{
return db.Areas.Where(x => x.ParentAreaID == null);
}
Upvotes: 6