I spend a lot of time today creating what seems in essence to be the same code over sand over again:
I’ve got an Datamodel that uses XPO (devexpress), I can not change that.
I created DTO’s, Services etc. for each separate XPO class like this
Task - XPO class
TaskDTO - POCO for Servicestack
TaskByKey - request to find a task by using it’s PK. PK always named OID, always with route “/Task/{Id}”
TaskByKeyResponse - the response to the request, always returning a TaskDTO (OID = 0 signals not found)
TaskServices - where the code sits to retrieve etc. the XPO record(s) and transfer (Convert) them to the DTO
The code for the service is below, my question is whether or not I can/should use AutoQuery (and how) to generate a generic solution to get this functionality?
public class TaakServices: Service
{
public object Any(TaakByKey request)
{
var taak = XafGlobal.securedObjectSpace.GetObjectByKey<Taak>(request.Id);
if (taak != null)
{
var result = taak.ConvertTo<TaakDTO>();
var back = new TaakByKeyResponse() { Result = result };
back.Result.OID = request.Id;
return back;
}
else
{
return new TaakByKeyResponse() { Result = new TaakDTO() { OID = 0 } };
}
}
}
Remarks: The ‘Any’ should probably be ‘Get’ and using Id in the route (instead of OID) is probably also not very consequent.