手机站
网通分站
电信主站
密 码:
用户名:
热门关键字:  虚拟主机  cn域名  asd  ddd  域名注册
当前位置 : 主页>程序设计>Java技术>列表

NHibernate(one-to-many)的问题

来源:互联网 作者:west263.com 时间:2008-02-23 点击:
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
<?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();

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

共2页: 上一页 1 [2] 下一页
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名
注册