Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

DataSourceResult with DTOs in ASP.NET

$
0
0

I'm attempting to populate a Kendo UI Grid with an object, however I'm using a DTO instead of the Entity Framework object that's defined in my database. The problem is that my DataSourceResult expects an object in the form of an IQueryable and my DTO is of a type List. Here is my Invoice object:

PublicClassInvoice
 
    <Key>
    PublicPropertyInvoiceID AsInteger
 
    PublicPropertyPrice AsDouble
 
    PublicPropertyAmountPaid AsDouble
 
    PublicPropertyStatus AsInvoiceStatus
 
    <StringLength(10000)>
    PublicPropertyMemo AsString
 
    PublicPropertyClient AsClient
 
    PublicPropertyClientID AsInteger
 
EndClass

And here is my DTO:

PublicClassInvoiceDTO
 
    PublicPropertyInvoiceID AsInteger
 
    PublicPropertyInvoiceDate AsDate
 
    PublicPropertyPrice AsDouble
 
    PublicPropertyAmountPaid AsDouble
 
    PublicPropertyStatus AsString
 
    PublicPropertyMemo AsString
 
    PublicPropertyClient AsString
 
    PublicPropertyClientID AsInteger
 
EndClass

I'm using the following code in my GET in my API to return the object to my Grid. I want to return a DataSourceResult as opposed to a List because I can use the paging and sorting functions to return data from my API as efficiently as possible.

<HttpGet, Route("api/client/all/invoices/{InvoiceStatus:int}")>
PublicFunctionGetInvoices(requestMessage AsHttpRequestMessage) AsDataSourceResult
 
 
    DimInvoices AsIEnumerable(Of Invoice) = _db.Invoices.Include("Client").OrderBy(Function(i) i.InvoiceDate)
 
    DiminvDTOs AsNewList(Of InvoiceDTO)
 
    ForEachinv AsInvoice InInvoices
        DiminvDTO AsNewInvoiceDTO
        invDTO.Client = inv.Client.Name
        invDTO.ClientID = inv.ClientID
        invDTO.Memo = inv.Memo
        invDTO.InvoiceDate = inv.InvoiceDate
        invDTO.Price = inv.Price
        invDTO.AmountPaid = inv.AmountPaid
        invDTO.Status = status(inv.Status)
 
        invDTOs.Add(invDTO)
    Next
 
    Dimresult AsNewDataSourceResult()
 
    result.Data = invDTOs
    result.Total = invDTOs.Count
 
    Dimresponse AsHttpResponseMessage = Request.CreateResponse(HttpStatusCode.Created, result)
 
    Return response
 
EndFunction

I can't query the DTO because it's a list. I can set the Data property of the DataSourceRequest to my DTO, however then I lose the paging functionality of the DataSourceRequest object built in that works well with the Grid. How do I use a DTO with the DataSourceResult?


Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>