I am trying to figure out a way to reference one entity from another using non-primary keys for both the referenced and referencing entities. I have the following:
public class UserContact
{
public virtual ulong ContactId { get; set;}
public virtual ulong UserId { get; set; }
public virtual ulong ContactUserId { get; set; }
}
public class EmergencyContact
{
public virtual ulong EmergencyContactId { get; set; }
public virtual ulong UserId { get; set; }
public virtual ulong EmergencyContactUserId { get; set; }
public virtual UserContact EmergencyUserContact { get; set; }
}
The mapping to UserContact actually uses a view, which ends-up duplicating records on the primary key (ContactId) on the actual table. (This is by design.)
I have the following mappings:
public class UserContactMap : ClassMap<UserContact>
{
public UserContactMap()
{
Table("USER_CONTACT_VW");
CompositeId().KeyProperty(x => x.ContactId, "CONTACT_ID")
.KeyProperty(x => x.UserId, "USER_ID");
Map(x => x.ContactUserId, "CONTACT_USER_ID")
}
}
public class EmergencyContactMap : ClassMap<EmergencyContact>
{
public EmergencyContactMap()
{
Table("EMERGENCY_CONTACT");
Id(x => x.EmergencyContactId, "EMERGENCY_CONTACT_ID");
Map(x => x.UserId, "USER_ID");
Map(x => x.EmergencyUserId, "EMERGENCY_USER_ID");
References(x => x.EmergencyUserContact)//.What else goes here?
}
}
I need to reference the UserContact within the EmergencyContact so that the UserId and EmergencyUserId from the EmergencyContact entity will map to the UserId and ContactUserId columns of the UserContact Entity. What is the best way to do this?