我现在有一张书籍表,和一张书籍类别表,主外键关系。
我现在想查所有数据,把类别也显示出来。书籍编号 书籍名称 书籍类别
110 天龙八部 武侠
111 逆龙道 都市BookInfo表
id,bookISBN,bookName,bid这个是 类别表的id.BookType表
id,type用NHibernate HQL语句。IList list = null;
ArrayList arr = new ArrayList();
try
{
ISession session = SessionFactory.OpenSession(_AssemblyName);
//string sql = "From LongFiction as a left join Fetch a.LongTypeInfo";
string sql = "From LongFiction as a,LongTypeInfo as b where a.LongTypeInfo =b.id";
list = session.CreateQuery(sql).List(); IEnumerator ie = list.GetEnumerator();
while (ie.MoveNext())
{
Object[] objs = (Object[])ie.Current;
LongFiction l = (LongFiction)objs[0];
LongTypeInfo info = (LongTypeInfo)objs[1];
UserCollection collection = new UserCollection(l, info);
arr.Add(collection);
}
}
catch (Exception ex)
{ throw;
} return arr;目前HQL语句不对。 list count是0 一条数据都没查出来
我现在想查所有数据,把类别也显示出来。书籍编号 书籍名称 书籍类别
110 天龙八部 武侠
111 逆龙道 都市BookInfo表
id,bookISBN,bookName,bid这个是 类别表的id.BookType表
id,type用NHibernate HQL语句。IList list = null;
ArrayList arr = new ArrayList();
try
{
ISession session = SessionFactory.OpenSession(_AssemblyName);
//string sql = "From LongFiction as a left join Fetch a.LongTypeInfo";
string sql = "From LongFiction as a,LongTypeInfo as b where a.LongTypeInfo =b.id";
list = session.CreateQuery(sql).List(); IEnumerator ie = list.GetEnumerator();
while (ie.MoveNext())
{
Object[] objs = (Object[])ie.Current;
LongFiction l = (LongFiction)objs[0];
LongTypeInfo info = (LongTypeInfo)objs[1];
UserCollection collection = new UserCollection(l, info);
arr.Add(collection);
}
}
catch (Exception ex)
{ throw;
} return arr;目前HQL语句不对。 list count是0 一条数据都没查出来
查询出bookinfo即可,实体类bookinfo会有一个属性及对应的booktype
BookInfo.bid=BookType.id