TXDataAureliusModel and TXDataModel

Hello Wagner,

is it possible to cast a TXDataModel to TXDataAureliusModel?

I load the model like from an example

  FXDataModel.Schemas.Clear;
  LResponse := xClient.HttpClient.Get( xClient.Uri + '/$model');
  try
    if LResponse.StatusCode = 200 then
      TXDataModelDeserializer.Deserialize( FXDataModel, TEncoding.UTF8.GetString( LResponse.ContentAsBytes))
    else
      TMessageDlg.Error( '$model kann nicht geladen werden.' + cStrCRLF +
                         'Url: ' + xClient.Uri + '/$model' + cStrCRLF +
                         'Code: ' + LResponse.StatusCode.ToString + cStrCRLF +
                         LResponse.StatusReason);
  finally
    LResponse.Free;
  end;

I need a TXDataAureliusModel to use with the IXDataQueryBuilder
CreateQuery( model).From ... works only if I call with a TXDataAureliusModel

See the sourcecode in XData.QueryBuilder

function TXDataQueryBuilder.From(const AClass: TClass): IXDataQueryBuilder;
var
  TargetType: TXDataStructuredType;
begin
  Result := Self;

  TargetType := nil;
  if FModel is TXDataAureliusModel then
  begin
    TargetType := TXDataAureliusModel(FModel).FindEntityTypeByClass(AClass);
    if TargetType = nil then
      TargetType := TXDataAureliusModel(FModel).FindInstanceTypeByClass(AClass);
  end;

  if TargetType = nil then
    raise EXDataQueryBuilderException.CreateFmt(SInvalidQueryType, [AClass.ClassName]);

  FBaseType := TargetType;
  FTypedQuery := FModel is TXDataAureliusModel;
end;

Thank you,
Thomas

Casting does not work.

Is there another way to get the XDataModel? To use the QueryBuilder (not the default model)

No, you cannot cast a TXDataModel to TXDataAureliusModel in this case. But why are you retrieving the model from the /$model endpoint? Can't you simply get the model from the TXDataClient object?

The sole purpose of /$model endpoint was to make it easier to use XData from TMS Web Core client applications.

Yes, I have the xDataClient.
But is there a function to get the model?

I found it, but it is protected

My solution is, that the creator (another unit) save the model and makes it available for retrieval later

Solved. Thank you.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.