I'm following this question: EF Code First - 1-to-1 Optional Relationship
And I have my relationships set up as follows:
public class Review {
[Key]
public int ReviewId { get; set; }
public virtual Payment Payment { get; set; }
}
public class Payment {
[Key]
public int PaymentId { get; set; }
[ForeignKey("Review")]
public int? ReviewId { get; set; }
public virtual Review Review { get; set; }
}
public class ReviewConfiguration : EntityTypeConfiguration<Review>
{
public ReviewConfiguration()
{
// One-to-One Optional
HasOptional<Payment>(s => s.Payment).WithOptionalDependent(s => s.Review).Map(s => s.MapKey("PaymentId"));
}
}
And I get ONE of the keys valid, but the other is never mapped as an optional FK:
What am I doing wrong?
I've seen some weird hacky solutions involving creating empty Lists etc - not what I'm looking for. I'm looking for a proper approach here - it has to exist... right?
Update
I'm using the above now - when I have the Payment on hand and need to access or delete the Review, I have to do another lookup on the [pseudo-FK] ReviewId, which totally sucks.