I have two classes and their relations are as below:
public class InteractiveObject
{
public int Id {get; set;}
public string Name{ get; set; }
public int? IndicatorId { get; set; }
public virtual Indicator Indicator { get; set; }
}
public class Indicator
{
public int Id {get; set;}
public string Name{ get; set; }
public int InteractiveObjectId { get; set; }
public virtual InteractiveObject InteractiveObject { get; set; }
}
And I configure it like
modelBuilder.Entity<Indicator>().HasRequired(x => x.InteractiveObject)
.WithOptional(x => x.Indicator);
It creates two tables that the table Indicator has not a nullable InteractiveObjectId, and table InteractiveObject has a nullable IndicatorId. Perfect.
But when I try to add Indicator with an InteractiveObject. The table Indicator contains the all information but the related InteractiveObject table does not contain IndicatorId. I mean IndicatorId is null on InteractiveObject table but InteractiveObjectId is not null on Indicator table
The code is like below:
modelBuilder.Entity<Indicator>().HasRequired(x => x.InteractiveObject)
.WithOptional(x => x.Indicator);
var selectedInteractiveObject = DbContext.Set<InteractiveObject>().FirstOrDefault(x => x.Id == 1);
var indicator = new Indicator { Name = "Test"};
selectedInteractiveObject.Indicator = indicator;
DbContext.SaveChanges();
InteractiveObjectId_Id. Did you check if your tables have foreign keys with underscores instead of the expectedInteractiveObjectId?