Yes, that's totally possible, unfortunately you can't rely on automatic foreign key and inverse relationship discovery, so you'll need to specify it manually.
For example, for a int
primary key and foreign keys declared like in the same class:
public class Body
{
[OneToOne(foreignKey: "LeftId", CascadeOperations = CascadeOperation.All)]
public Hand Left { get; set; }
[OneToOne(foreignKey: "RightId", CascadeOperations = CascadeOperation.All)]
public Hand Right { get; set; }
// Foreign key for Left.Id
public int LeftId { get; set; }
// Foreign key for Right.Id
public int RightId { get; set; }
}
public class Hand
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
}
If your foreign keys are declared in Hand
object the attribute properties are equivalent:
public class Body
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[OneToOne(foreignKey: "LeftId", CascadeOperations = CascadeOperation.All)]
public Hand Left { get; set; }
[OneToOne(foreignKey: "RightId", CascadeOperations = CascadeOperation.All)]
public Hand Right { get; set; }
}
public class Hand
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
// Foreign key for Body.Id where this object is Left
public int LeftId { get; set; }
// Foreign key for Body.Id where this object is Right
public int RightId { get; set; }
}
And inverse properties, if needed, must be specified in the inverseProperty
key of the OneToOne
attribute of both ends:
public class Body
{
// Skipping foreign keys and primary key
[OneToOne(foreignKey: "LeftId", inverseProperty: "LeftBody", CascadeOperations = CascadeOperation.All)]
public Hand Left { get; set; }
[OneToOne(foreignKey: "RightId", inverseProperty: "RightBody", CascadeOperations = CascadeOperation.All)]
public Hand Right { get; set; }
}
public class Hand
{
// Skipping foreign keys and primary key
[OneToOne(foreignKey: "LeftId", inverseProperty: "Left", CascadeOperations = CascadeOperation.All)]
public Body LeftBody { get; set; }
[OneToOne(foreignKey: "RightId", inverseProperty: "Right", CascadeOperations = CascadeOperation.All)]
public Body RightBody { get; set; }
}