0

This question deals with the different "size" of a returned JSON result from these two difference controllers (API vs OData).
Some entities for example: (this is a bad composition and it was only made for making a point, please don't judge to relation between these entities)

public class Customer
{
    public string Name { get; set; }
    public Category Category { get; set; }
}

public class Category
{
    public string CategoryName { get; set; }
    public List<Customers> CustomersInCategory { get; set; }
}

When making a GET request to an OData controller, say:

GET http://localhost:81/Customers

The result will not contain the Customers' Category object, unless I explicitly mention "$expand=Category" on the URL.

However, The same request for an API controller, will return the Customers' Category object (even if the result is IQueryable<Customer>). The problem with this is that in case of cyclic relations between entities, the result is recursively flatten in becomes enormous (might be infinity).
I've been looking for a solution for this problem all over and found stuff like MaxDepth that doesn't work and many other things that resulted nothing.

What I really want is a way to "tell" the API controller or its methods, to "DO not expand the result" - or better yet, ignore cyclic referencing (which I've also tried and didn't work).

UPDATED: Here is the GET method on the API controller:

[HttpGet]
[ActionName("DefaultAction")]
public IQueryable<Customer> Get()
{
     return _unitOfWork.Repository<Customer>().Query().Get();
}

Thanks.

Tomer
  • 4,382
  • 5
  • 38
  • 48

0 Answers0