Multiple return types from NHibernate
Earlier I asked this question: Loop in MySql, or alternative? I got a great answer and it does work. Now in my application I am using NHibernate(in C# .NET 3.5) as the DAL. I dont really know how to deal with multiple return types, so I tried the following:
var session = NHibernateHelper.GetCurrentSession();
IQuery query = session.CreateSQLQuery(@"SELECT * FROM tableA AS A
LEFT JOIN tableB AS ctrl1 ON (A.controlID = ctrl1.controlID AND ctrl1.controlOptionType = ? AND ctrl1.controlOptionValue = ?)
LEFT JOIN tableB AS ctrl2 ON (A.controlID = ctrl2.controlID AND ctrl2.controlOptionType = ? AND ctrl2.controlOptionValue = ?)")
.AddEntity(typeof(nodecontrol));
IList<tableA> aList = query.List<tableA>();
IList<tableB> bList = query.List<tableb>();
This worked with aList. But when I add another "AddIdentity" for tableB it dies when it gets to the aList part because its the wrong type of object. Now I presume I can just do a linq WHERE on that List to get the types for each(but I dont know how), and after that, how do I differentiate from the two instances of tableB that I will get per row?
Preferably I would like to end up with 3 l开发者_如何学编程ists(tableA, tableB, tableB) where the rows are inline so aList[4] will be the same result row as bList1[4] and bList2[4].
Thanks :)
I believe Multi Query is the solution that you're looking for.
精彩评论