0

Currently I am using aspnetboilerplate to enhance a project which include both mvc and web api, after port web api code to abp, I found the controller cannot return entity successfully, the code like below:

public IQueryable<SomeEnity> GetEntities()
{
    return _repository.GetAll().Where(e => e.TagId == 1);
}

The exception from postman is popular:

The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.

After some searching, I get it work with introducing a SomeEntityDto (another class), because the entity number for the web api so many that I don't want introduce so many dto for each entity.

The question is: Why the same code work with original project (EF and ASP.NET MVC) but failed with abp framework? Any solution?

Note: I also tried this, but not work.

James Hao
  • 765
  • 2
  • 11
  • 40
  • Why are you returning `IQueryable`? – aaron Aug 09 '18 at 13:17
  • A lot of desktop applications (legacy) connect to original web api which will be replaced with abp, in order to make the response the same as the original web api, I don't change the return type. – James Hao Aug 09 '18 at 15:52
  • It will be evaluated anyway. Why not return a list of entities? Btw, that's returning your whole table of `SomeEntity`. – aaron Aug 09 '18 at 16:04
  • It's a bad practise to return a queryable. You should consider changing your clients. Return List – Alper Ebicoglu Aug 10 '18 at 05:53
  • plus; when you want to get a list of child entities after you get the IQueryable, your dbcontext will be disposed and you will be getting `The operation cannot be completed because the DbContext has been disposed` – Alper Ebicoglu Aug 10 '18 at 05:58

0 Answers0