I have two tables with the details as shown here, which have a one-to-one relationship with one another.
public partial class Concept : AuditableWithBaseEntity<decimal>
{
public string Code { get; set; }
public decimal ConceptnodeId { get; set; }
public virtual Conceptnode Conceptnode { get; set; }
}
public partial class Conceptnode : BaseEntity<decimal>
{
public decimal ConceptId { get; set; }
public int Presentationorder { get; set; }
public virtual Concept Concept { get; set; }
}
When I try to insert data with this code:
Concept targetConcept = new()
{
Code = currTC.Code,
Conceptnode = new Conceptnode()
{
presentationOrder = currTC.presentationOrder
}
};
_dbContext.Concepts.Add(targetConcept)
_dbContext.SaveChanges();
I get an error:
An error occurred while saving the entity changes. See the inner exception for details.
The INSERT statement conflicted with the FOREIGN KEY constraint "conceptnls_fk2". The conflict occurred in database "DB_P20", The statement has been terminated.
Is there any other way to use for such scenario.
Thanks in advance.