I've noticed questions that have answered this problem for earlier beta versions of EF 7 (like here), but I haven't seen it solved for Beta 7, so here it goes:
I have 2 entities, simplified as follows:
public class FirstEntity
{
public int FirstEntityID { get; set; }
/*
Other fields here
*/
public int? SecondEntityID { get; set; }
public SecondEntity SecondEntityProperty { get; set; }
}
public class SecondEntity
{
public int FirstEntityID { get; set; }
/*
Other fields here
*/
public FirstEntity FirstEntityProperty { get; set; }
}
The way to map everything has changed so much from earlier versions. How do I map these two entities in a One-to-One relationship?
It has been changed for EF7 rc1-final.
modelBuilder.Entity<FirstEntity>()
.HasOne(q => q.SecondEntity)
.WithMany()
.HasForeignKey(q => q.SecondEntityID);
upd:
modelBuilder.Entity<FirstEntity>()
.HasOne(q => q.SecondEntity)
.WithOne(v => v.FirstEntity)
.HasForeignKey<FirstEntity>(q => q.SecondEntityID);