SelectMany() Cannot Infer Type Argument — Why Not?

前端 未结 1 870
無奈伤痛
無奈伤痛 2020-12-09 14:50

I have an Employee table and an Office table. These are joined in a many-to-many relationship via the EmployeeOffices table.

I

相关标签:
1条回答
  • 2020-12-09 15:29

    The type returned by the delegate you pass to SelectMany must be an IEnumerable<TResult>, but evidently, Office doesn't implement that interface. It looks like you've simply confused SelectMany for the simple Select method.

    • SelectMany is for flattening multiple sets into a new set.
    • Select is for one-to-one mapping each element in a source set to a new set.

    I think this is what you want:

    foreach (var office in CurrentEmployee.EmployeeOffices.Select(eo => eo.Office))
    
    0 讨论(0)
提交回复
热议问题