Search code examples
c#asp.netapiodatarestier

How have more than two expands in restier asp.net


I have a RESTier service and I need to use more than two expand in browser Url like below:

http://localhost:64747/api/SI24/Customers?$filter=Id%20eq%2067922&$expand=Bns($expand=Parvandes($expand=ParvandeStateLogs))

I must not make any controller for this service. If you see in my url you can understand that I must navigate between four tables. The tables are Customers , Bns , Parvandes , ParvandeStateLogs. How can I solve this problem?


Solution

  • I myself against my will decided to make one controller for this query and added the attribute of "[EnableQuery(MaxExpansionDepth = 50)]" over its action as below:

    public class CustomersController : ODataController
    {
        private SI24 db = new SI24();
    
        // GET: api/Customers
        [EnableQuery(MaxExpansionDepth = 50)]
        public IQueryable<Customer> GetCustomers()
        {
            return db.Customers;
        }
    }