FNH에서 다음 테이블/엔티티를 매핑하려고하는데 아무데도 빨리 보이지 않는 것 같습니다!Fluent NHibernate Mapping - Composite Key
**Tables**
Contacts
ID (PK - int - generated)
...
PhoneTypes
ID (PK - varchar - assigned) (e.g. MOBILE, FAX)
ContactPhones
ContactRefId (PK - FK to Contacts)
PhoneTypeRefId (PK - FK to PhoneTypes)
...
나는, 복합 IDS 작업 다른 컴포지트 ID를 분리 할 때 좋습니다 읽었
**Entities**
public class Contact : Entity
{
(The ID property is defined in the Entity base class and is type int)
public virtual ICollection<ContactPhone> PhoneNumbers { get; set; }
}
public class PhoneType : EntityWithTypedId<string>, IHasAssignedId<string>
{
(The ID property is defined in the base class and is type string)
....
}
public class ContactPhone : EntityWithTypedId<ContactPhoneId>, IHasAssignedId<ContactPhoneId>
{
public virtual Contact Contact { get; set; }
public virtual PhoneType PhoneType { get; set; }
....
}
(나는 또한 S 번호의 ARP 아키텍처 프레임 워크를 사용하고 있음을 유의하십시오) 수업. hibernate composite key
public class ContactPhoneId : EntityWithTypedId<ContactPhoneId>, IHasAssignedId<ContactPhoneId>
{
public virtual Contact Contact { get; set; }
public virtual PhoneType PhoneType { get; set; }
}
...I could just make this class serializable and override
Equals and GetHashCode myself instead of using the S#arp Arch base class.
나는 지금 완전히 혼란 스러워요 매핑의 많은 조합을 시도했습니다.
Foreign key (FK672D91AE7F050F12:ContactPhones [ContactRefId, PhoneTypeRefId]))
must have same number of columns as the referenced primary key (Contacts [Id])
사람이 분명 아무것도 보이지 않는다 : I는 최신있는 매핑을 생성하려고 할 때 많은 예외가 슬로우 했어
public class ContactMap : IAutoMappingOverride<Contact>
{
public void Override(AutoMapping<Contact> mapping)
{
mapping.HasMany<ContactPhone>(x => x.PhoneNumbers)
.KeyColumns.Add("ContactRefId")
.KeyColumns.Add("PhoneTypeRefId")
.AsSet()
.Inverse()
.Cascade.All();
}
}
public class PhoneTypeMap : IAutoMappingOverride<PhoneType>
{
public void Override(AutoMapping<PhoneType> mapping)
{
mapping.Id(x => x.Id).Column("Id").GeneratedBy.Assigned();
}
}
public class ContactPhoneMap : IAutoMappingOverride<ContactPhone>
{
public void Override(AutoMapping<ContactPhone> mapping)
{
mapping.Table("ContactPhones");
mapping.CompositeId<ContactPhoneId>(x => x.Id)
.KeyReference(y => y.Contact, "ContactRefId")
.KeyReference(y => y.PhoneType, "PhoneTypeRefId");
}
}
:
이 내 최신 샷 내가 잘못하고있어? 나는 NH와 FNH가 처음인데,이 게시물에서 분명히 알 수 있습니다. :-) 또한 S # arp Architecture를 사용하는 동안 누구나 복합 ID를 사용 했습니까? 가장 좋은 방법은 무엇입니까 (대리 키를 사용하는 것 외 :-))?
많은 감사와 긴 게시물에 대해 유감입니다.