Field values when using projections

I am trying to populate a DBGrid with a result set from an Aurelius ORM query.

This is the SQL that works:
  select max(c_date), st.last, st.first, st.id_student from tblContact c
  inner join tblstudent st on st.id_student = c.id_student
  group by st.id_student
  order by c_date

To start, I created a simple query with no projections:
  AureliusDataset2.SetSourceCriteria(AMgr.Find<TtblContact>().OrderBy('c_date'));
This populates the grid with values.

But when I tried to add my "group by" and "max" projections, nothing displays in my DBGrid: 
  AureliusDataset2.SetSourceCriteria(AMgr.Find<TtblContact>()
    .SetProjections(TProjections.ProjectionList
    .Add(TProjections.Group('id_student'))
    .Add(TProjections.Max('c_date')))
    .OrderBy('c_date')
    );

I also tried it with DBAdvGrid, with same results.

What is missing from my ORM query that I get a list of records but no fields in my grid?

Thanks in advance to everyone for your help.  I learn a lot from following your posts.

Hello Jon,

When using projections (TCriteriaResult objects) you have to create the the dataset fields yourself in advance. Just use aliases and create fields with names, i.e.:



 AureliusDataset2.SetSourceCriteria(AMgr.Find<TtblContact>()
    .SetProjections(TProjections.ProjectionList
    .Add(TProjections.Group('id_student').As_('student'))
    .Add(TProjections.Max('c_date').As_('maxdate')))
    .OrderBy('c_date')
    );


For example, create two fields, student and maxdate in your dataset.

For the benefit of future souls... So if a given query has projections then Arelius doesn't return entities. But we can still output data to the dataset for DB aware components by creating aliases for the fields we want?

Yes, correct.