We want to reference a inherited Control in Completion because one Control has a list of possible Completions and saves the selected Completion. Our tables are
public class Completion
{
public int CompletionId { get; set; }
public string Text { get; set; }
public virtual Control Control { get; set; }
}
public class Control : BaseControl
{
public int ControlId { get; set; }
public virtual Completion Completion { get; set; }
public virtual ICollection<Completion> Completions { get; set; }
}
the migration of these tables works, but if we try to add a Completion to the database, we get the exception
{"SQLite Error 1: 'foreign key mismatch - \"Completion\" referencing \"Control\"'"}
we add a Completion like this
var completion = new Completion { Text = "completion1" }; db.Completions.Add(completion); db.SaveChanges();
Aucun commentaire:
Enregistrer un commentaire