OData and XData

Hi,

When data is retrieved the reponse includes the count as @xdata.count: 111

In the xdata server is there any way that this text can be modified as it is not recognisable as a count using OData.

Thanks,

Kne

Hi @Randall_Ken, there is no easy way to change in automatic CRUD endpoints. XData is not compatible with OData though, there are other things that are different.

One thing you can do is simply create a service operation and return a DTO that expects the JSON in the exact format OData expects.

Thanks. In my service I am jst using a TAureliusConnection connected to a NexusDB database.

Can you please give me a clue on how to implement thsi?

Here is an example of a DTO:

  [JsonInclude(TInclusionMode.Always)]
  [JsonManaged]
  TResultList<T: class> = class
  strict private
    [JsonProperty('@count')]
    FCount: Assignable<Integer>;

    [JsonProperty('value')]
    FValue: TList<T>;
  public
    constructor Create; 
    destructor Destroy; override;
    property Count: Assignable<Integer> read FCount write FCount;
    property Data: TList<T> read FData;
  end;

constructor TResultList<T>.Create;
begin
  inherited Create;
  FValue := TObjectList<T>.Create(AOwnsObjects);
end;

destructor TResultList<T>.Destroy;
begin
  FValue.Free;
  inherited;
end;

Then just create any service operation that returns it:

  function TMyService.SomeData: TResultList<TMyObject>;

And just make sure to return such object properly filled.

Thanks. I'll try this.

This won't work for me. I need to call the normal crud endpoint e.g.

http://localhost:2001/tms/xdata/Patients?$select=ID,HospitalNo,LastName,FirstName

but replace the automatic response (change xdata to odata).

You can't change the normal crud endpoint. You should replace it with a service operation to override its behavior.