Gigi2m02
Gigi2m02

Reputation: 1268

Mapping two foreign keys to one primary key (XML Mapping)

I've searched a lot after a solution for this, but the only thing that came out was a solution with FH-mapping instead of XML-mappng. I'm working with a QR-scanning system where two users can scan eachother. If one user shoots an other user their id got filled in in this table. So the two FK's will be unique together. 1-2. 2-1, 1-3 So my domain actually contains this two classes:

public class SnappedUsers
{
    public virtual User Shooter {get; set;}
    public virtual User Target { get; set; }
    public virtual DateTime SnapDate { get; set; }
}
public class User : Entity
{
    public virtual string DisplayName { get; set; }
    public virtual string EmailAddress { get; set; }
    public virtual string Password { get; set; }
    public virtual string ProfilePicUrl { get; set; }
    public virtual int Money { get; set; }
    public virtual DateTime RegistrationDate { get; set; }
}

The table SnappedUsers should contain two foreign keys from the User table. (it's not necessary that i put an Shooter ISet and an Target ISet to my User class.) How do i actually have to map these things with XML-mapping? I don't see a solution myself for now.

Thx in advance

Upvotes: 0

Views: 625

Answers (1)

Firo
Firo

Reputation: 30813

<composite-id> 
  <key-many-to-one name="Shooter" column="shooter_Id" >
  <key-many-to-one name="Target" column="target_Id" />
</composite-id>

Upvotes: 2

Related Questions