Control expand level and proxy in service implementation

I'm looking for a way to adjust service implementation by service implementation the activation and level of expand

In my service I get something similar to

Result := TXDataOperationContext.Current.GetManager.Find<TReparateur>.Where(TLinq.Eq('reparateur_id', Id)).UniqueResult;

TReparateur gets couples of sub linked object in different proxy (SiteList, ReparateurContactList...)
I would like to expand only for this service this level
But using Where () I don't find way to process

I tried without success each of these :

  • TXDataOperationContext.Current.GetManager.ProxyListLoadDepth := 3;
  • TXDataOperationContext.Current.GetManager.ProxyLoadDepth := 3;
  • TXDataOperationContext.Current.Response.Headers.SetValue('xdata-expand-level', '3');

How to process (without setting up a genaral parameter in XdataServer or using $expand param) ?


I tried without success too

TXDataOperationContext.Current.Response.Headers.SetValue('xdata-expand-level', '3');

I'm still without expanding list

    "$id": 1,
    "reparateur_id": 104,
    "ReparateurContactList@xdata.proxy": "Reparateur(104)/ReparateurContactList",
    "ReparateurFicheMetierList@xdata.proxy": "Reparateur(104)/ReparateurFicheMetierList",
    "ReparateurRibList@xdata.proxy": "Reparateur(104)/ReparateurRibList",
    "SiteList@xdata.proxy": "Reparateur(104)/SiteList"

Have you tried using the three options at the same time? It should work. Note that the xdata-expand-level header should be set in the request, not in the response.

Alternatively you can force the proxies to be loaded using the manager (setting xdata-expand-level is still needed):

Result := TXDataOperationContext.Current.GetManager
  .Where(TLinq.Eq('reparateur_id', Id)).UniqueResult;
TXDataOperationContext.Current.Request.Headers.SetValue('xdata-expand-level', '3');

You can always have the option of using DTO objects to fully customize the way you want the response should be.

Hi Wagner
Thanks for answer
But unfortunately I still get none expand on using

Result := TXDataOperationContext.Current.GetManager.Find<TReparateur>.FetchEager('ReparateurContactList').FetchEager('SiteList').Where(TLinq.Eq('IdAffaire', IdAffaire)).UniqueResult;
TXDataOperationContext.Current.Request.Headers.SetValue('xdata-expand-level', '3');

Proxy are here but not expanded

. . .
 "ReparateurContactList@xdata.proxy": "Reparateur(115)/ReparateurContactList",
  "ReparateurFicheMetierList@xdata.proxy": "Reparateur(115)/ReparateurFicheMetierList",
  "ReparateurRibList@xdata.proxy": "Reparateur(115)/ReparateurRibList",
  "SiteList@xdata.proxy": "Reparateur(115)/SiteList"

Using expand value in SwaggerUI works fine but goals here is to force expand without parameter in URL


In other hand if I put setting

TXDataOperationContext.Current.GetManager.ProxyListLoadDepth := 3;
TXDataOperationContext.Current.GetManager.ProxyLoadDepth     := 3;
TXDataOperationContext.Current.Request.Headers.SetValue('xdata-expand-level', '3');

The proxies are expanded but without control and request seems very heavy on DB
But limitation is sub object with proxy dont seems expanded (Reparateur > Site > SiteContactList)

Is there a setting on xdataserver that prevents expanding proxy list like "$expand" URL param ?


We have detected here there is an issue with FetchEager and many-valued association. Indeed, the method doesn't have any effect on lists and thus it's always being loaded in lazy mode which causes it to not be expanded.

We will fix this in the next release, so you will be able to accomplish what you want using FetchEager and then setting the proper expand level. However, I still think that if you need the JSON output to be in a specific format, even without user choosing what he wants, you should consider using a DTO with the exact format you want.