Projecting the Type of a class

22 views
Skip to first unread message

xanatos

unread,
Nov 8, 2012, 7:42:24 AM11/8/12
to nhu...@googlegroups.com
Vehicle as various subclasses (Car, Truck, ...)

In this query the tuple.Third will contain the discriminator of the Vehicle class. I want it to contain the class Type. NHibernate does have it (because it can create the correct classes), what I need is a type converter or a projection or something similar... Or perhaps it isn't possible? Thanks!

    NHibernate.Linq.Tuple<string, string, object> tuple = null;

    var res = s.QueryOver<Vehicle>()
        .SelectList(p => p
            .Select(q => q.Owner).WithAlias(() => tuple.First)
            .Select(q => q.Vin).WithAlias(() => tuple.Second)
            .Select(q => q.GetType()).WithAlias(() => tuple.Third)
)
        .TransformUsing(Transformers.AliasToBean<NHibernate.Linq.Tuple<string, string, object>>())
        .List<NHibernate.Linq.Tuple<string, string, object>>();

xanatos

unread,
Nov 8, 2012, 7:43:45 AM11/8/12
to nhu...@googlegroups.com
Clearly it should be Vehicle HAS various subclasses (Car, Truck, ...) :-)
Reply all
Reply to author
Forward
0 new messages