I have a mapped model with Nhibernate like this:
public class A
{
public virtual long Id { get; set; }
public virtual long Number { get; set; }
/* and other 20 properties... */
}
public class B
{
public virtual long Id { get; set; }
public virtual A ItemA { get; set; }
public virtual string Name { get; set; }
public virtual DateTime Date { get; set; }
}
I would like to create a query (queryover, linq, hql etc… anyway) to get a List<B> and fill ItemA property with just Id and Number properties because I need only this properties (I have lots of properties in A class and I will not use it on my results). Is there any way to do this or should I create a ViewModel? If I need to create a ViewModel, how can I do this with QueryOver?
Thank you!
Yes, you have to create a view model, like following:
Now you oculd query it with linq like this: