Type 'System.Linq.EnumerableQuery` is an invalid collection type since it does not have a valid Add method

  • 826
  • 0

Type 'System.Linq.EnumerableQuery`  is an invalid collection type since it does not have a valid Add method

I'm using OData with get mehod and parameter ?$top=2  but get error message:

<ExceptionMessage>
Type 'System.Linq.EnumerableQuery`1[[TestObj, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' is an invalid collection type since it does not have a valid Add method with parameter of type 'TestObj'.
</ExceptionMessage>

 

finally I found that it is because the return type of get method using List<TestObj>

public List<TestObj> Get()

Modify it to IEnumerable then the problem is solved.

public IEnumerable<TestObj> Get()