Mapping foreign key in HasOptional().WithOptionalDependent() relation in Entity Framework 6

后端 未结 2 524
没有蜡笔的小新
没有蜡笔的小新 2021-01-08 00:32

I have the following data-model in Entity Framework 6.1.3:

using System.Data.Entity;

public class Student
{
    public int Id { get; set; }
    public virtu         


        
2条回答
  •  孤城傲影
    2021-01-08 01:13

    I managed to get a response from the Entity Framework Program Manager after asking on GitHub.

    Unfortunately this is a limitation of EF6. You can not have a foreign key property in a one-to-one relationship, unless it is also the primary key property. This is essentially because EF6 doesn't support alternate keys/unique indexes, so you can't enforce that a non-primary key property is unique. The fact that you can do it when the foreign key property isn't in the entity is a bit of a quirk... but obviously not something we would remove

提交回复
热议问题