Sergio Tapia
Sergio Tapia

Reputation: 41208

The type arguments for method cannot be inferred from the usage. Try specifying the type arguments ex - error. Any guidance?

    /// <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

Answers (2)

minimalis
minimalis

Reputation: 1953

I think you want to use Where:

return db.Areas.Where(x => x.ParentAreaID == null)

Upvotes: 2

dtb
dtb

Reputation: 217361

Enumerable.SelectMany:

Projects each element of a sequence to an IEnumerable<T> and flattens the resulting sequences into one sequence.

Enumerable.Where:

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

Related Questions