ここで必要なのは、PlayerBowlerType で使用する複合 ID です。このセットアップは機能するはずです:
public class PlayerBowlerTypeId
{
public virtual int PlayerId { get; set; }
public virtual int BowlerTypeId { get; set; }
public override bool Equals(object obj)
{
return Equals(obj as PlayerBowlerTypeId);
}
private bool Equals(PlayerBowlerTypeId other)
{
if (ReferenceEquals(other, null)) return false;
if (ReferenceEquals(this, other)) return true;
return PlayerId == other.PlayerId &&
BowlerTypeId == other.BowlerTypeId;
}
public override int GetHashCode()
{
unchecked
{
int hash = GetType().GetHashCode();
hash = (hash * 31) ^ PlayerId.GetHashCode();
hash = (hash * 31) ^ BowlerTypeId.GetHashCode();
return hash;
}
}
}
public class PlayerBowlerType
{
public PlayerBowlerType()
{
Id = new PlayerBowlerTypeId();
}
public virtual PlayerBowlerTypeId Id { get; set; }
}
public class PlayerBowlerTypeMap : ClassMap<PlayerBowlerType>
{
public PlayerBowlerTypeMap()
{
Table("TABLENAME");
CompositeId<PlayerBowlerTypeId>(x => x.Id)
.KeyProperty(x => x.BowlerTypeId, "COLUMNNAME")
.KeyProperty(x => x.PlayerId, "COLUMNNAME");
}
}
技術的にはアイデンティティ オブジェクトなしでこれを行うことができます (PlayerBowlerTypeId 型は削除され、コードは PlayerBowlerType に直接配置され、適切に調整されます) が、これを行うことによって引き起こされるいくつかの問題 (3-4 の個別のバグ) がありました。そのうちの 1 つをここで説明します。
ORM システムのバグを補うためにドメイン オブジェクトを変更するのは嫌いですが、PlayerBowlerTypeId 型を使用するだけで、多くの頭痛の種から解放されます。
実際のテーブル名と列名を使用するようにマッピングを変更する限り、これは機能するはずです (および特定のセットアップのマッピングで行う必要があるその他すべて)。