tags:

views:

13

answers:

1

Hi, Suppose there is table (Tbl_Test) with 7 columns A,B,C,D,E,F,G and similarly there is an Entity class with all these as its attributes a,b,c,d,e,f,g.

If I query the table using Nhibernate to fetch a record:

IQuery query = session.CreateQuery("select I.A, I.B, I.C from Tbl_Test I where I.D :xyz");

"Suppose there is only one record in the table with D column's value as some XYZ"

Now what will be the value of the attributes of the entity class.

Will the attributes apart from a,b,c (that is the attributes d,e,f and g) will have the value as null for the fetched object.

+1  A: 
IQuery q = session.CreateQuery ("select new MyEntityView(a, b, c) from Entity");

where

  • MyEntityView is a class you create which has properties to hold those values that you want to retrieve. Also, you must make sure that this class has an appropriate constructor
  • Entity is the full-fledged Entity that you've mapped.

You can also achieve this by using the ICriteria API. I've elaborated more on that here.

Frederik Gheysels