I am using NHibernate with an SQL query to populate some entity objects.
I have an Item object that references a User object (specify the owner of the element)
class Item { public User User; }
My SQL query (this is actually more complicated, so I canβt use HQL, but I started with this to make sure AddJoin / AddEntity works):
SELECT {i.*}, {u.*} FROM Item i INNER JOIN User u ON (i.UserId = u.Id) WHere i.Id = 5
Here is my code:
var x = session.CreateSQLQuery(sql) .AddEntity("i", typeof(Item)) .AddJoin("u", "i.User") .List();
When I run this, I get a two-dimensional array. Each element of the array contains an Item object (with an initialized User property) and the User object itself.
What am I missing? I was hoping to get a list of Item objects with an initialized User property (thatβs how I interpreted the documentation).
nhibernate
Mark sherretta
source share