Increase Speed of LoadSchema

RODA Gurus,

I have a WebvService (ie wsCopyEntity), which has the purpose of copying the given record(s) in a master table and all its respective detail records. This method is generic such that any record of any table can be copied thru this function. This method uses TDAMemDataTables which are bound to a LocalDataAdapter as follows:

begin
lcdsSrc := TDAMemDataTable.Create(self);
lcdsDst := TDAMemDataTable.Create(self);
try
  // INTERATE THRU EACH MASTER PK
  lEntityName := aCopyEntity.zMaster;
  lEntityNV     := aCopyEntity.zNameValue;
  // CDS TO COPY FROM
  lcdsSrc.LogicalName := lEntityName;
  lcdsSrc.RemoteFetchEnabled := True;
  lcdsSrc.RemoteDataAdapter  := lLDA;
  lcdsSrc.LoadSchema;        // TAKES ~5sec
  lcdsSrc.DynamicWhere.Clear;
  lWhereSrc := lcdsSrc.DynamicWhere;
  // CDS TO COPY INTO
  lcdsDst.LogicalName := lEntityName;
  lcdsDst.RemoteFetchEnabled := True;
  lcdsDst.RemoteDataAdapter  := lLDA;
  lcdsDst.LoadSchema;         // TAKES ~5sec
  lcdsDst.DynamicWhere.Clear;

This snippet of code is called in a loop recursively As currently designed this method works. However, the LoadSchema calls each take ~5 seconds time the number or records. So a given request takes several minutes.

QUESTION:
How can I change the design to speed the LoadSchema calls?

Thank You.
Monte Carver

some workarounds:

  1. if table has no fields, they will be read at opening table. as a result LoadSchema isn’t needed.
  2. the same logical name is used for both tables so
lcdsDst.Fields.AssignFieldCollection(lcdsSrc.Fields);

can be used instead of loading schema.
3) schema for both tables can be loaded in one call like

lda.FillSchema([lcdsSrc, lcdsDst]);
  1. if lda references to the same service, fields can be assigned manually like
//lDataTableSchema: TDADataset;
lDataTableSchema := self.ServiceSchema.Datasets.FindDatasetByName(lEntityName);
lcdsSrc.Fields.AssignFieldCollection(lDataTableSchema.Fields);

Excellent answers. Thank You for the paradigm shift…