示例
多主键的表例如map如下
public class JxPermissionMap : ClassMap<JxPermission>
{
public JxPermissionMap()
{
Table("JX_Permission");
LazyLoad();
CompositeId().KeyProperty(x => x.PermissionID, "PermissionID")//KeyProperty自身主键,
.KeyReference(x => x._User, "StaffidID");//KeyReference为外键关联主键,
//_User为另一个表的model
Map(x => x.FunctionName).Column("FunctionName").Length(20);
Map(x => x.State).Column("State");
}
}
JxPermission model
public class JxPermission
{
public virtual int PermissionID { get; set; }
public virtual JxOutpatientuser _User { get; set; }
public virtual string FunctionName { get; set; }
public virtual bool State { get; set; }
#region NHibernate Composite Key Requirements
public override bool Equals(object obj)
{
if (obj is JxPermission)
{
var toCompare = obj as JxPermission;
return this.GetHashCode() != toCompare.GetHashCode();
}
return false;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion
}
关联的JxOutpatientuser 对象,
public class JxOutpatientuser
{
public JxOutpatientuser()
{
_ListPermissions = new List<JxPermission>();
}
public virtual IList<JxPermission> _ListPermissions { get; set; }
}
JxOutpatientuser相关的map添加
HasMany(x => x._ListPermissions).KeyColumn("StaffidID").Cascade.All().NotFound.Ignore();