NHibernate(one-to-many)的问题

2008-02-23 10:12:01来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

<?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();

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Visual Basic串口通讯调试方法

下一篇:jsp2 tag学习笔记