0
I’m having a hard time making one Insert, because the FE indicates that there is error in the table reference. But, in my config, I state what is the foreing key.
My config:
public class TestDriveConfig : EntityTypeConfiguration<TestDrive>
{
public TestDriveConfig()
{
ToTable("TestDrive");
HasKey(p => p.Id);
Property(p => p.Id).IsRequired();
Property(p => p.ExpireDate).IsRequired();
Property(p => p.OpeningDate).IsRequired();
Property(p => p.UserId).IsRequired();
HasRequired(p => p.User).WithMany().HasForeignKey(a => a.UserId);
}
}
The error that the RU presents when performing the Insert:
"Foreign key Violation [Testdrive :: Userid]. The key value [2] does not exist in the referenced table [vw__usuario :: code].. Error code: Relationerror"
Does your database already have data? It seems to me that this error comes from trying to create an external key pointing to an item that does not exist.
– RSinohara
I tested working with tests, I insert data, then insert into this table.
– Vinícius
I think you entered an external key value 2 for user before creating or changing the interface. The RU cannot create the interface because this external key would point to a line that does not exist.
– RSinohara
You can put both Models in your question?
– Leonel Sanches da Silva
Solved the problem? Otherwise, you can put the class code in the question to try to help you?
– Renan