it:ad:asp.net:webapi:howto:use_odata_and_dtos

IT:AD:ASP.NET:WebAPI:HowTo:Use OData and DTOs

A key goal would be to use a Repository, returning DTO's to external services. That's a bit tougher.

Example:

The trick is that the Constructor is creating queryable property.. That can later be exposed over the wire. Neat.

    public class DataModel
    {
      public DataModel()
      {
      using (var dbContext = new ODataDemoEntities())
      {
        Invoices = 
        dbContext.Invoices
        //.Include("LineItems")
        //.Where(i=>i...)
        //.Skip(...)
        //.Take(...)
        .Select(i=> {return _DataMappingService.Map<InvoiceDTO>(i))
      }
      }
      public IQueryable<EmployeeDTO> Invoices { get; private set; }
    }

* Found it (later, mind you!) here: http://stackoverflow.com/a/9806623

  • /home/skysigal/public_html/data/pages/it/ad/asp.net/webapi/howto/use_odata_and_dtos.txt
  • Last modified: 2023/11/04 02:15
  • by 127.0.0.1