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