Paging Results


For some reason Take(20) is not working for me.

  AddDataView('item.all',
    function(AViewName: string; AParam: Variant): INaharDataView
    begin
      result := InstanceDataView;
      result.AsCriteria := OManager.Find<TEntityItem>.Take(20);

      AddDominioCriteria(result);
    end);

I use a way in my software to register each possible "view" of data, to operate like services.

That result.AsCriteria is just a variable to hold the operation and be used across the application, as an Interface. 

That AddDominioCriteria is:

  ADataView.AsCriteria.Add(TLinq.Eq('Dominio', Context.Dominio));

so at the end i have

OManager.Find<TEntityItem>.Take(20).TLinq.Eq('Dominio', Context.Dominio).Open;

and apply that to the TAureliusDataset (it has no filters)

It always retrieve all the data from the table. Whatever value that I use beisdes 20.

Does the order of the commands make difference? How can I get on Aurelius to find what is the problem?

Eduardo


You use TAureliusDataset.SetSourceCriteria method?

Did you try to check what is the exact SQL generated by that criteria?

I am using SetSourceCriteria.


I have implemented the Listerners to get the SQL, I  have found other things also.

First, the Take(20) does not show in the SQL:
Debug Output:
2014-07-22 21:27:31:432  [] [Aurelius SQL] SELECT A.PJIDITEM AS A_PJIDITEM, A.CODIGOFABRICANTE AS A_CODIGOFABRICANTE, A.NAOINCLUIRINVENTARIO AS A_NAOINCLUIRINVENTARIO, A.NAOVENDERESTOQUEZERO AS A_NAOVENDERESTOQUEZERO, A.NAOUSARETIQUETA AS A_NAOUSARETIQUETA, A.NAOALTERARABC AS A_NAOALTERARABC, A.UNIDADEEQUIVALENCIA AS A_UNIDADEEQUIVALENCIA, A.PESO AS A_PESO, A.COMPRIMENTO AS A_COMPRIMENTO, A.LARGURA AS A_LARGURA, A.ALTURA AS A_ALTURA, A.VOLUME AS A_VOLUME, A.DISPONIVEL AS A_DISPONIVEL, A.TIPOPRODUTO AS A_TIPOPRODUTO, B.ID AS B_ID, B.DOMINIO AS B_DOMINIO, B.OWNER AS B_OWNER, B.CODIGO AS B_CODIGO, B.NOME AS B_NOME, B.DESCRICAO AS B_DESCRICAO, B.REFERENCIA AS B_REFERENCIA, B.ATIVO AS B_ATIVO, B.NAOVENDER AS B_NAOVENDER, B.PRECOVENDA AS B_PRECOVENDA, B.AJIDGRUPO AS B_AJIDGRUPO, B.AJIDICMS AS B_AJIDICMS, B.AJIDITEMVENDA AS B_AJIDITEMVENDA, A.AJIDUNIDADEUSO AS A_AJIDUNIDADEUSO, A.AJIDUNIDADECOMPRA AS A_AJIDUNIDADECOMPRA, A.AJIDMARCA AS A_AJIDMARCA, A.AJIDFABRICANTEROTULO AS A_AJIDFABRICANTEROTULO
FROM ITEMPRODUTO 
Process NaharFMX.exe (1844)
Debug Output: 2014-07-22 21:27:31:438  [] [Aurelius SQL Param] p_0 = "1" (ftInteger) Process NaharFMX.exe (1844)

The process of opening my Item Edit Form was too slow, first I was thinking that is because Aurelius was retrieving the entire table, that is really happening but the problem is something else.

After this Select is done, Aurelius start querying this select:

Debug Output:
2014-07-22 21:27:31:747  [] [Aurelius SQL] SELECT A.PICTURE As f0_
FROM ITEM A
  LEFT JOIN ITEMSERVICO B ON (B.PJIDITEM = A.ID)
  LEFT JOIN ITEMPRODUTO C ON (C.PJIDITEM = A.ID)
WHERE  A.ID = :p_0
Process NaharFMX.exe (1844)
Debug Output: 2014-07-22 21:27:31:752  [] [Aurelius SQL Param] p_0 = "{006CE261-B582-44FD-A852-F4065F287092}" (ftGuid) Process NaharFMX.exe (1844)

FOR EACH ITEM ON THE TABLE !

TAureliusDataSet is connected to a BindSource that is connected to a TListVIew

When I remove the bind link from my TEntityItem.Picture to the Item.Bitmap on the Listview this loop of queries stops.

Picture is declared:

    FPicture: TBlob;

public
    [Column('PICTURE', [TColumnProp.Lazy])]
    property Picture: TBlob read GetPicture write SetPicture;

What I could learn from it is that TColumnProp.Lazy when removed this problem gone, because the SQL was generated including the Picture.

That is the expected behavior?

Back to the original question, why take(20) is not there?

Another question on that is: Do I need to really have to page for each 20 items for example? How is that done? can I when reach EOF try another page? I am not sure how to deal with that in a way more fluent, I believe the Entities in memory should be created progressively when needed for such a case.

Thanks

Eduardo

Yes, it's expected behavior. If the property is marked as lazy, it will be retrieved separated when it's needed. 


I don't know why Take(20) is not working, it should work flawlessly (our tests indicate it's working, at least in the conditions of our tests). We need more info to investigate.

You don't "need" to page results. You just page if you want to. When you use SetSourceCriteria and set Page property of TAureliusDataset, paging is performed automatically (regardless if your original TCriteria had a Take method call before). It's just a different way to perform data on demand. Instead of having an active, online cursor open in database, paging results allow you to avoid loading all data at once, but at the same time allows you to get offline (when dataset needs another set of data, it will perform another sql).