SelectMany() Cannot Infer Type Argument — Why Not?

前端 未结 1 873
無奈伤痛
無奈伤痛 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, 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)
提交回复
热议问题