我发现了类似的问题,但我卡住了。
我正在构建 API 休息,当我尝试添加迁移时出现此错误
“SessionSpeaker.Speaker”和“Speaker”之间以及“SessionSpeaker”和“Speaker.SessionSpeakers”之间的关系都可以使用 {'SpeakerId'} 作为外键。要解决此问题,请在至少一个关系上显式配置外键属性。
我已经看到了有关它的答案,但它不起作用):
//楷模:
public class Speaker : PlanificadorDTO.Speaker
{
public virtual ICollection<SessionSpeaker> SessionSpeakers { get; set; } = new List<SessionSpeaker>();
}
public class SessionSpeaker
{
public int SessionId { get; set; }
public Session Session { get; set; }
public int SpeakerId { get; set; }
public Speaker Speaker { get; set; }
}
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
////cuando se cree el modelo en Entity.. …Run Code Online (Sandbox Code Playgroud)