How to do this SQL on Aurelius

Hi,

How can I do this query using Aurelius, I Allready have an Entity TIMAGEN for table IMAGENES
Or how can I select the first record only. 

SELECT FIRST 1 ID_MESA FROM IMAGENES WHERE TIPO = :TIPO AND
PROCESADA = 0

Any hint?

Thanks in Advance,

Omar Zelaya

There you go:


Imagen := Manager.Find<TImagen>
  .Take(1)
  .Where(TLinq.Eq('Tipo', tipo) and TLinq.Eq('Processada', 0))
  .UniqueResult;

It's always a good idea to define an order (using OrderBy) when taking the first object.

Hi Wagner,

Thanks!...and could this be done also:

SELECT FIRST 1 ID_MESA FROM IMAGENES,MESAS_ELECTORALES,CENTROS_VOTACION,MUNICIPIOS WHERE IMAGENES.TIPO = 1 AND
IMAGENES.PROCESADA = 0 AND IMAGENES.ID_MESA = MESAS_ELECTORALES.ID AND MESAS_ELECTORALES.ID_CENTRO_VOTACION =
CENTROS_VOTACION.ID AND CENTROS_VOTACION.ID_MUNICIPIO = MUNICIPIOS.ID AND MUNICIPIOS.ID_DEPTO = 5

Thanks in advance,

Omar Zelaya

Hi, have you looked in deep the chapter about creating queries? 

http://www.tmssoftware.biz/business/aurelius/doc/web/index.html?queries.htm

that SQL is somewhat rather simple to achieve using Aurelius criteria, using CreateAlias in case you want to reach out the Municipio.DeptoId.
Without knowing how your mapping is, it's hard to build the exact criteria for it.

Here is the specific topic about querying by properties of associated entities:


http://www.tmssoftware.biz/business/aurelius/doc/web/index.html?expression_in_associations.htm