NHibernate中对于多字段主键的Maping:
以下代码通过测试的
SumupCarte.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Cash.Domain.SumupCarte, Cash.Domain" table="sumup_carte">
<composite-id >
<key-property name="Sid">
<column name="sid" sql-type="decimal" length="18" not-null="true"/>
</key-property>
<key-property name="Cid">
<column name="cid" sql-type="decimal" length="18" not-null="true" />
</key-property>
<key-property name="IsCountermand">
<column name="IsCountermand" sql-type="tinyint" length="1" not-null="true" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
SumupCarte.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Cash.Domain
...{
[Serializable]
public class SumupCarte: Entity
...{
Private Fields#region Private Fields
private System.Decimal _sid;
private System.Decimal _cid;
private System.Byte _isCountermand;
#endregion

Property Members#region Property Members
public virtual System.Decimal Sid
...{
get...{ return this._sid; }
set...{ this._sid = value; }
}
public virtual System.Decimal Cid
...{
get...{ return this._cid; }
set...{ this._cid = value; }
}
public virtual System.Byte IsCountermand
...{
get...{ return this._isCountermand; }
set...{ this._isCountermand = value; }
}
#endregion
public override bool Equals(object obj)
...{
if (base.Equals(obj)) return true;
if (obj == null) return false;
SumupCarte eb = (SumupCarte)obj;
return eb.Sid.Equals(this.Sid);
}
public override int GetHashCode()
...{
return Sid.GetHashCode();
}
}
}
本文介绍如何使用NHibernate实现多字段主键的映射,并提供了一个具体实例,包括XML配置文件和对应的C#类定义。
306

被折叠的 条评论
为什么被折叠?



