여기서 필요한 것은 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 가지 버그). 그 중 하나가 here으로 논의됩니다.
ORM 시스템의 버그를 보완하기 위해 도메인 객체를 변경하는 것을 싫어하지만 PlayerBowlerTypeId 유형을 사용하면 많은 두통을 피할 수 있습니다.
실제 테이블과 열 이름을 사용하도록 매핑을 수정하는 한 (그리고 특정 설정에 대해 매핑 작업과 관련하여 필요한 작업을 수행해야하는 경우) 작업해야합니다.