【发布时间】:2016-03-13 12:02:55
【问题描述】:
我们希望在 Completion 中引用继承的 Control,因为一个 Control 具有可能的 Completion 列表并保存选定的 Completion。 我们的桌子是
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; }
}
这些表的迁移是可行的,但是如果我们尝试向数据库添加 Completion,则会出现异常
{"SQLite 错误 1: '外键不匹配 - \"Completion\" 引用 \"Control\"'"}
我们添加这样的 Completion
var completion = new Completion { Text = "completion1" };
db.Completions.Add(completion);
db.SaveChanges();
【问题讨论】:
标签: c# entity-framework sqlite uwp