NHibernate(one-to-many)的问题

王朝java/jsp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

<class name="RG.SuperStarOA.Customers.Data.Customers,WebApplication1" table="Customers">

<id name="CustomerID" column="CustomerID" type="String" length="5">

<generator class="assigned" />

</id>

<set name="Orders" >

<key column="CustomerID" />

<one-to-many class="RG.SuperStarOA.Orders.Data.Orders,WebApplication1" />

</set>

<property name="CompanyName" column="CompanyName" type="String" length="40"></property>

<property name="ContactName" column="ContactName" type="String" length="30"></property>

<property name="ContactTitle" column="ContactTitle" type="String" length="30"></property>

<property name="Address" column="Address" type="String" length="60"></property>

<property name="City" column="City" type="String" length="15"></property>

<property name="Region" column="Region" type="String" length="15"></property>

<property name="PostalCode" column="PostalCode" type="String" length="10"></property>

<property name="Country" column="Country" type="String" length="15"></property>

<property name="Phone" column="Phone" type="String" length="24"></property>

<property name="Fax" column="Fax" type="String" length="24"></property>

</class>

</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

<class name="RG.SuperStarOA.Orders.Data.Orders,WebApplication1" table="Orders">

<id name="OrderID" column="OrderID" type="Int32" length="4">

<generator class="identity" />

</id>

<many-to-one name="Customers" column="CustomerID" class="RG.SuperStarOA.Customers.Data.Customers,WebApplication1" />

<property name="CustomerID" column="CustomerID" type="String" length="5"></property>

<property name="EmployeeID" column="EmployeeID" type="Int32" length="2"></property>

<property name="OrderDate" column="OrderDate" type="DateTime" length="4"></property>

<property name="RequiredDate" column="RequiredDate" type="DateTime" length="4"></property>

<property name="ShippedDate" column="ShippedDate" type="DateTime" length="4"></property>

<property name="ShipVia" column="ShipVia" type="Int32" length="4"></property>

<property name="Freight" column="Freight" type="Decimal" length="4"></property>

<property name="ShipName" column="ShipName" type="String" length="40"></property>

<property name="ShipAddress" column="ShipAddress" type="String" length="60"></property>

<property name="ShipCity" column="ShipCity" type="String" length="15"></property>

<property name="ShipRegion" column="ShipRegion" type="String" length="15"></property>

<property name="ShipPostalCode" column="ShipPostalCode" type="String" length="10"></property>

<property name="ShipCountry" column="ShipCountry" type="String" length="15"></property>

</class>

</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

<class name="RG.SuperStarSystem.Shippers.Data.Shippers,WebApplication1" table="Shippers">

<id name="ShipperID" column="ShipperID" type="Int32" length="4">

<generator class="identity"/>

</id>

<property name="CompanyName" column="CompanyName" type="String" length="40"></property>

<property name="Phone" column="Phone" type="String" length="24"></property>

</class>

</hibernate-mapping>

//下面这段代码执行就完全没有问题

private void Button3_Click(object sender, System.EventArgs e)

{

NHibernate.Cfg.Configuration c = new NHibernate.Cfg.Configuration();

c.AddXmlFile(System.Web.HttpContext.Current.Server.MapPath("Customers.xml"));

c.AddXmlFile(System.Web.HttpContext.Current.Server.MapPath("Orders.xml"));

c.AddXmlFile(System.Web.HttpContext.Current.Server.MapPath("Shippers.xml"));

ISession vSession= c.BuildSessionFactory().OpenSession();

ITransaction vTransaction = vSession.BeginTransaction();

try

{

IList data = vSession.Find("from Shippers");

DataGrid1.DataSource = data;

DataGrid1.DataBind();

vTransaction.Commit();

}

catch(Exception ex)

{

vTransaction.Rollback();

Response.Write(ex.Message);

}

finally

{

vSession.Close();

}

}

//这段代码去老是提示:Could not execute query

private void Button2_Click(object sender, System.EventArgs e)

{

NHibernate.Cfg.Configuration c = new NHibernate.Cfg.Configuration();

c.AddXmlFile(System.Web.HttpContext.Current.Server.MapPath("Customers.xml"));

c.AddXmlFile(System.Web.HttpContext.Current.Server.MapPath("Orders.xml"));

c.AddXmlFile(System.Web.HttpContext.Current.Server.MapPath("Shippers.xml"));

ISession vSession= c.BuildSessionFactory().OpenSession();

ITransaction vTransaction = vSession.BeginTransaction();

try

{

IList data = vSession.Find("from Customers");

DataGrid1.DataSource = data;

DataGrid1.DataBind();

vTransaction.Commit();

}

catch(Exception ex)

{

vTransaction.Rollback();

Response.Write(ex.Message);

}

finally

{

vSession.Close();

}

}

我测试来测试去,都是觉得是

<set name="Orders" >

<key column="CustomerID" />

<one-to-many class="RG.SuperStarOA.Orders.Data.Orders,WebApplication1" />

</set>

或者,写查询语句有问题?

谁能解决,拜托~`

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有