Entity Framework .net: "The Name value should be a valid navigation property name."
Ok. I've solved this issue. Just in case anyone have the same problem, here is the problem and the answer:
I had my entities like:
namespace PlataformaTest.Models{ public class AnswerModel { public int Id { get; set; } public string UserId { get; set; } [ForeignKey("OptionModel"), Column(Order = 0)] public int QuestionId { get; set; } [ForeignKey("OptionModel"), Column(Order = 1)] public int OptionId { get; set; } [JsonIgnore] public virtual OptionModel OptionModelEx { get; set; } }}
But I found out, that
ForeignKey("OptionModel")
has to have the same name of the "Virtual" variable. Like this:
namespace PlataformaTest.Models{ public class AnswerModel { public int Id { get; set; } public string UserId { get; set; } [ForeignKey("OptionModel"), Column(Order = 0)] public int QuestionId { get; set; } [ForeignKey("OptionModel"), Column(Order = 1)] public int OptionId { get; set; } [JsonIgnore] public virtual OptionModel OptionModel { get; set; } }}
I thought it had to have the name of the Class, but it doesn't. It looks for the name of the object to map the Entity's Foreign Key.