一对多时的Load主对象总是提示“一个参数没有被指定值”

我配置了Order表与OrderItem表的一对多关系,但在Load时总是出错。以下是部分测试代码:

COrder order = null;
try
{
    order 
= (COrder)session.Load(typeof(COrder),1);
}
catch(Exception ee)
{
    Console.WriteLine(ee.ToString());
}
finally
{
    
if(order!=null)
        Console.WriteLine(
string.Format("ID={0} and Items.Count={1}",order.ID,order.Items.Count));
    
    session.Close();
}

总在order = (COrder)session.Load(typeof(COrder),1)这行,提示
NHibernate.ADOException: could not initialize collection: [EnPrint.DB.COrder.Items#1] ---> System.Data.OleDb.OleDbException: 至少一个参数没有被指定值。
的错误信息。

检查其Sql语句,明显不是我所期待的
NHibernate :SELECT corder0_.ID as ID0_, corder0_.Customer_ID as Customer2_0_, corder0_.BuildDate as BuildDate0_ FROM [Order] corder0_ WHERE corder0_.ID=?

NHibernate :SELECT items0_.ID as ID__, items0_.OrderItem_ID as OrderIte1___, items0_.OrderItem_ID as OrderIte1_1_, items0_.Price as Price1_, items0_.Quantity as Quantity1_, items0_.Product_ID as Product_ID1_, items0_.Order_ID as Order_ID1_, corder1_.ID as ID0_, corder1_.Customer_ID as Customer2_0_, corder1_.BuildDate as BuildDate0_ FROM OrderItem items0_ left outer join [Order] corder1_ on items0_.Order_ID=corder1_.ID WHERE items0_.ID=?
第二行语句的Where语句总应是“where item0_.Order_ID=?”吧?

我使用过1.0和1.0.1的版本都是如此。纳闷中....
posted @ 2006-01-11 09:50  生命体验之kevin-Y  阅读(1311)  评论(1编辑  收藏  举报