Let's say we have this
class A
{
[Key]
public int Id { get; set; }
public string X { get; set; }
public string Y { get; set; }
public B B;
}
class B
{
[Key]
public int Id { get; set; }
public string X { get; set; }
public string Y { get; set; }
public virtual ICollection<A> As { get; set; }
}
Assume that pairs of X and Y are guaranteed to be unique in B, thus {X, Y} could be a composite primary key on B but isn't, Id is.
Is it possible with Fluent API to express that A.B should be a navigation property via this fake foreign key relationship?
Something like this, except it doesn't work:
HasRequired(a => a.B).WithMany(b => b.As).HasForeignKey(a => new { a.X, a.Y })