ASP.NET Core API oData and API layer model

Web Technologies Web Development 2 years ago

0 0 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I need to use OData for my API endpoints in ASP.NET Core application, but all examples are about working directly with Data Model classes. In my application architecture I has service layer, methods of this service return DTO classes and then map to API view classes. My data class (infrastructure layer): public partial class Carrier : BaseEntity { public string Name { get; set; } public string Code { get; set; } public string UsDotNumber { get; set; } public string McNumber { get; set; } My DTO class: public class CarrierBaseDto { public int Id { get; set; } public string Name { get; set; } public string Code { get; set; } public string Fein { get; set; } public string McNumber { get; set; } My presentation (API) class: public class CarrierAPI { [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "code")] public string Code { get; set; } [JsonProperty(PropertyName = "fein")] public string Fein { get; set; } [JsonProperty(PropertyName = "mcNumber")] public string McNumber { get; set; } my service method: public List SearchCarriersDto() { var query = _context.Carriers .Where(c => !c.Deleted); IQueryable queryDto = query.ProjectTo(_mapperConfig); return queryDto.ToList(); } My controller method: [HttpGet] [Route("GetAll")] public IActionResult GetAll() { var carriers = _carrierService.SearchCarriersDto(); var carriersApi = _mapper.Map>(carriers); return new OkObjectResult(carriersApi); } I want to add abilities to use $orderBy, $filter, $fields params. How to add it to my current architecture?

Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (0)

Post Answer

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Web Technologies Links