I am using NHibernate with a SQL query to populate some entity objects.
I have an Item object which references a User object (to indicate the owner of the Item)
class Item
{
public User User;
}
My SQL query is (it's actually more complicated, which is why I can't use HQL, but I started with this to make sure the AddJoin/AddEntity was working):
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 item in the array contains an Item object (with the User property initialized) and the User object itself.
What am I missing? I was hoping to get a list of Item objects with the User property initialized (which is how I interpreted the documentation).