NHibernate(one-to-many)的问题
2008-02-23 10:12:01来源:互联网 阅读 ()
<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
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:jsp2 tag学习笔记
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash