public IHttpActionResult Get(string sort = "id", string fields = null) { try { bool includeBooks = false; List <string> lstOfFields = new List <string>(); // we will include the books if the fields contains businesses if (fields != null) { lstOfFields = fields.ToLower().Split(',').ToList(); includeBooks = lstOfFields.Any(f => f.Contains("books")); } IQueryable <Repository.Entities.Customer> customers = null; if (includeBooks) { customers = _repository.GetCustomersWithBooks(); } else { customers = _repository.GetCustomers(); } return(Ok(customers.ApplySort(sort).ToList() // returns a list of our businesscategories from entities, however we want to return it from our DAO/// we map it in the next line (We want the models from our DAO. .Select(eg => _customerFactory.CreateDataShapedObject(eg, lstOfFields)))); // we map the entities to there coresponding DAO Models: So, For each businesscategory we call factory and return new businesscategory model //for each businesscategory we call factory we say create businesscategory that accept business category entity and returns business category DAO } catch (Exception) { return(InternalServerError()); } }