/*
* Description: In hql, left Outer Join is used to connect multiple objects * auther: the sky is blue _ Chong
* MSN: chongchong2008@msn.com
* Dates: 2006-05-22
* Copyright: chongchong2008 Yichang Hubei China
*/
When you use left outer join to connect multiple objects, note that the returned ilist or ienumerable is not directly an object, but a multi-dimensional array. Pay attention to this in 1.1, otherwise, it is difficult to find the error.
I will introduce it as follows:
Descriptions is an ilist type attribute of wordentity, that is, descriptions in wordentity is a one-to-many thing.
Public static ilist getwrod (String title)
{
simplequery q = new simplequery (
typeof (wordentity), typeof (ilist),
// "from wordentity word where word. Title like? ", // If left Outer Join is not added, the output will have content
@" from wordentity word left Outer Join word. Descriptions description where word. Title like? And word. descriptionid in elements (word. descriptions) ", // with this output, there is no information. You can
title
of the petroleum information in the data table);
return (ilist) executequery (Q );
}
The returned ilist is actually an object [] []. Obviously it does not meet our requirements. What we need is a set object.
So how can we convert the returned two-dimensional array to our object set? Come with me ....
Ilist wordlist = wordentity. getword ("Web % ");
Int maxindex = wordlist. Count * 2;
Response. Write (wordlist. Count. tostring () + "---" + wordlist. GetType (). tostring () + "</BR> ");
Wordentity Mya;
Arraylist myas = new arraylist ();
Descriptionentity myb;
Int II = 1;
Foreach (object [] O in wordlist)
{
Mya = new wordentity ();
Response. Write (O. tostring () + "</BR> ");
Foreach (Object OO in O)
{
Response. Write ("no." + II. tostring () + "element start" + "</BR> ");
If (II % 2! = 0)
{
If (II <= maxindex)
{
Response. Write (wordentity) Oo). wordtitle + "</BR> ");
Mya. wordtitle = (wordentity) Oo). wordtitle;
}
}< br> else
{< br> myb = new descriptionentity ();
myb. descriptioncontent = (descriptionentity) Oo ). descriptioncontent;
Mya. descriptions. add (myb);
Response. Write (descriptionentity) Oo). descriptioncontent + "</BR> ");
Myas. Add (Mya );
}
Response. Write ("no." + II. tostring () + "element end" + "</BR> ");
II ++;
}
}
Now, we can use foreach to traverse the process ~~~
Foreach (wordentity we in myas)
{
Response. Write (We. wordtitle + "</BR> ");
Foreach (descriptionentity D in we. Descriptions)
{
Response. Write (D. descriptioncontent + "</BR> ");
Response. Write (D. descriptiondate. tostring ("yyyy-m-dd") + "</BR> ");
}
Response. Write ("<p> </P> ");
}