1
votes

I'm trying to run the code below, but I'm getting an error on the first SelectMany statement: "The type arguments for method 'IEnumerable<TResult> System.Linq.Enumerable.SelectMany...' cannot be inferred from the usage. Try specifying the type arguments explicitly". Company has a list of Employments, I want to get a list with all employments of the company called "Company1", and after I need to filter with the employee is currently working (when EndDate is null) and return a list only with their names.

I need to do it using Linq Queries.

var employees = FindAllCompanies()
            .Where(x => x.Name == "Company1")
            .SelectMany(x => x.Employments)
            .Select(x => x.EmploymentEndDate == null)
            .SelectMany(x.Name);
1

1 Answers

8
votes

I think you have a typo, instead of

.Select(x => x.EmploymentEndDate == null)

you want

.Where(x => x.EmploymentEndDate == null)

If you select this you will get a bool, that has not a Name property, of course.

The final SelectMany is also wrong, instead of

.SelectMany(x.Name)

this

.Select(x => x.Name)