尝试创建具有多值外键的一对多关系时出现以下错误...
**
SQLite.Net.SQLiteException:外键不匹配 - “活动”引用“节点”
**
这是表 SQL(为清楚起见进行了简化)...
CREATE TABLE [Activity] (
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[InstId_FK] numeric(18,0) NOT NULL,
[NodeSeq_FK] numeric(3,0) NOT NULL,
[ActivityType] int NOT NULL,
CONSTRAINT [Node_FK] FOREIGN KEY([InstId_FK], [NodeSeq_FK]) REFERENCES [Node]([ID], [NodeSeq])ON DELETE CASCADE);
CREATE TABLE [Node] (
[ID] NUMERIC(18) NOT NULL CONSTRAINT [ID] REFERENCES [Trip]([ID]) ON DELETE CASCADE,
[NodeSeq] numeric(3,0) NOT NULL,
[Status] int,
[Name] nvarchar(30) NOT NULL,
CONSTRAINT [sqlite_autoindex_TripNode_1] PRIMARY KEY ([ID], [NodeSeq]));
还有我的 C# 模型(为清楚起见再次简化)...
public class TripNodeActivity : LocationAware
{
[PrimaryKey, AutoIncrement, ForeignKey(typeof(Node),Order = 1)]
public int Id { get; set; }
[Column("InstId_FK")]
public int InstIdFk { get; set; }
[Column("NodeSeq_FK"), ForeignKey(typeof(Node),Order = 2)]
public int NodeSeqFk { get; set; }
public int ActivityType { get; set; }
}
public class Node
{
public Node(){Activity = new List<Activity>();}
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<Activity> Activity{get;set;}
[PrimaryKey, ForeignKey(typeof(Trip))]
public int Id { get; set; }
[PrimaryKey]
public int NodeSeq { get; set; }
public int Status { get; set; }
public String Name { get; set; }
}
尝试使用以下方法保存模型时会发生此错误:
SQLiteConnection.InsertOrReplaceWithChildren(NodeFromAbove,true)