views:

56

answers:

2

I have the following collection ( see image ) . I wish to parse this into List. I have tried NHibernate's "Transformers.AliasToBean"

Like so var result = _session.CreateQuery(hql) .SetResultTransformer(Transformers.AliasToBean(typeof(OrderProduct))) .List();

Tho i'm getting the following error:

Could not find a setter for property '0' in class 'EStore.Domain.Projection.OrderProduct'

At this stage i would settle for just parsing this into the List. How can i do this with linq?alt text

public class OrderProduct
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public  decimal  Quantity { get; set; }
    }
+1  A: 

Wouldn't something like that be working?

        var test = from object[] line in results
                   select new OrderProduct()
                   {
                       Id = (int)line[0],
                       Name = (string)line[1],
                       Quantity = (decimal)line[2]
                   };
Gimly
+1  A: 

In order to use AliasToBean, you need to explicitly assign aliases to your selection list:

select p.Id as Id,
       p.Name as Name,
       etc
Diego Mijelshon