Search code examples
c#activerecordnhibernatehql

query with two table result mapping


I created a hql query, which has a result with two tables. Now I want to map my result in an iterable list.

        string hql = "select distinct l, b from Lieferung as l " +
                     "inner join l.Bestellung as b";
        var hbq = new HqlBasedQuery(typeof(Lieferung), @hql);
        hbq.SetResultTransformer(Transformers.AliasToEntityMap);
        var result = ActiveRecordMediator.ExecuteQuery(hbq);

Now I want to iterate through my result with a foreach loop. But it doesn't work. I don't now how I can map my result in something like:

        IList<Tuple<Lieferung, Bestellung> result
        //or
        IList<Result> result
        public class Result //or struct
        {
            Lieferung Lieferung;
            Bestellung Bestellung;
        }

Solution

  • Try the following:

    List<Lieferung> list = new List<Lieferung>(results.Count);
    for (int i = 0; i < results.Count; i++)
    {
        list.Add((Lieferung)results[i]);
    }