This is probably very simple and I’ll end up with a red face…
class Person {
public Guid Id {get;set;}
public string Name {get;set;}
public Person Manager {get;set;} // The person may or may not have a manager.
public Guid? ManagerId {get;set;} // I need the Guid if the Person has a manager
}
I tried
modelBuilder.Entity<Person>().HasOptional(e=>e.Manager).WithMany().HasForeignKey(e=>ManagerId)
but that didn’t do any good.
Have you tried without any custom relationship mapping? I would have thought the ef would automatically do it’s magic for you.
If not change you class as folows and you won’t need to configure any of the relationships. It might be ef code first does not like guids
Do you have a specific reason for using a guid and not int?