62,272
社区成员
发帖
与我相关
我的任务
分享
public class Account
{
// Id
public virtual string UserId { get; set; }
// 密码
public virtual string Password { get; set; }
// 状态
public virtual int State { get; set; }
// 关联基本信息
public virtual DetailInfo Detail { get; set; }
}
public class DetailInfo
{
public virtual Guid Id { get; set; }
// 地址
public virtual string ShopAddress { get; set; }
// Email
public virtual string Email { get; set; }
// QQ号
public virtual string QQ { get; set; }
// 关联的登录账号
public virtual Account RelAccount { get; set; }
} <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="WebTest"
namespace="WebTest">
<class name="Account" table="Account">
<id name="UserId" column="UserId" type="String">
<generator class="assigned" />
</id>
<property name="Password" type="String"/>
<property name="State" type="Int32" />
<!--关联基本信息-->
<one-to-one name="Detail" class="DetailInfo" cascade="all-delete-orphan" lazy="proxy"
property-ref="RelAccount" />
</class>
</hibernate-mapping><?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="WebTest"
namespace="WebTest">
<class name="DetailInfo" table="DetailInfo">
<id name="Id" column="Id" type="Guid" >
<generator class="assigned" />
</id>
<property name="ShopAddress" type="String" />
<property name="QQ" type="String" />
<property name="Email" type="String" />
<many-to-one name="RelAccount" class="Account" column="UserId" unique="true" />
</class>
</hibernate-mapping> string id = "dd";
string pwd = "BB";
string email = "ee";
string qq = "CCC";
string shopAddress = "DE";
DetailInfo detail = new DetailInfo
{
Email = email,
QQ = qq,
ShopAddress = shopAddress,
Id = Guid.NewGuid()
};
Account account = new Account
{
UserId = id,
Password = pwd,
State = 1,
};
account.Detail = detail;
detail.RelAccount = account;
ISession s = SessionProvider.GetSession();
using (ITransaction tr = s.BeginTransaction())
{
s.SaveOrUpdate(account);
s.Flush();
tr.Commit();
}