There is a code:
public enum ErrorType { CodeIsMissing, ConversionCodeIsMissing, UpdateError} public class Dict { [Key] public string Code { get; set; } [Required] public string Name { get; set; } } public class Record { [Key] public string Code { get; set; } } public class Error { public Dict Dict { get; set; } public Record Record { get; set; } [Required] public DateTime Date { get; set; } [Required] public ErrorType Type { get; set; } public bool Corrected { get; set; } [ForeignKey("Dict")] public string DictCode { get; set; } [ForeignKey("Record")] public string RecordCode { get; set; } } Suppose the database already has a record of the Dict object with Code = "Code1" and a record of the Record object with RecordCode = "RecordCode". Now I want to add an object of the class Error to the base, which has a Dict object with Code = "Code1" and a Record object with RecordCode = "RecordCode". When saving, the error "Violation of PRIMARY KEY constraint 'PK_dbo.Dicts'. Cannot insert duplicate key in object 'dbo.Dicts'. The duplicate key value is (Code3). \ R \ nThe statement has been terminated." How to avoid trying to re-insert existing records?