I try to use one-to-many relationship in Entity Framework 6 and I got an error Invalid column name 'MeetingStatusObj_Id
, but if you see below I already using [ForeignKey("blabla")]
to explicitly set the column name.
It looks like Entity Framework is ignoring the [ForeignKey("blabla")]
for some reason.
BUT if I set the relationship using FluentAPI
it will works perfectly. Am I missing something ?
here is my code.
public class MeetingDetail
{
[Key]
public Guid Id { get; set; }
[Required]
public int IdMeetingStatus { get; set; }
[ForeignKey("IdMeetingStatus")]
public MeetingStatus MeetingStatusObj { get; set; }
}
public class MeetingStatus
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public IList<MeetingDetail> MeetingDetailObj { get; set; }
}
//In class AppDBContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Prevent error https://stackoverflow.com/a/6143116/7906006
Database.SetInitializer<AppDbContext>(null);
base.OnModelCreating(modelBuilder);
//If i set the relationship using fluent API in here, it will work perfectly
}
EDIT :
Other annotations is not working too like [Column("YourColumnName")]
, [NotMapped]