請原諒的代碼在牆上,但我需要設置舞臺....多對多關係在SQLite的擴展不更新
public class Student
{
public string Name { get; set; }
[PrimaryKey]
public string Id { get; set; }
[ManyToMany(typeof(StudentStaff))]
public List<Staff> Teachers { get; set; }
[ManyToMany(typeof(StudentGuardian))]
public List<Guardian> Guardians { get; set; }
}
public class Guardian
{
[PrimaryKey]
public string Id { get; set; }
public string Name{get;set;}
[ManyToMany(typeof(StudentGuardian))]
public List<Student> Students { get; set; }
}
public class Staff
{
[PrimaryKey]
public string Id { get; set; }
public string Name { get; set; }
[ManyToMany(typeof(StudentStaff))]
public List<Student> Students { get; set; }
}
public class StudentStaff
{
[ForeignKey(typeof(Student))]
public string StudentId { get; set; }
[ForeignKey(typeof(Staff))]
public string StaffId { get; set; }
}
public class StudentGuardian
{
[ForeignKey(typeof(Student))]
public string StudentId { get; set; }
[ForeignKey(typeof(Guardian))]
public string GuardianId { get; set; }
}
鑑於這些,我應該怎麼插入的學生,工作人員及監護人類進入數據庫,同時保持關係?我應該注意到服務器返回填充的學生記錄,所以這是我的出發點。
我試過conn.InsertOrReplaceWithChidlren(student);
...插入了學生,學生和學生監護人記錄,但不是實際的工作人員或監護人。 我試圖 conn.InsertOrReplaceWithChildren(student);
conn.InsertOrReplaceWithChildren(student.Teachers);
conn.InsertOrReplaceWithChildren(student.Guardians);
奇怪的是,結束了工作人員,監護人和老師插入,但沒有交集表中的任何數據...
--update --- 我只是想 conn.InsertOrReplaceWithChildren(student.Teachers);
conn.InsertOrReplaceWithChildren(student.Guardians);
conn.InsertOrReplaceWithChildren(student);
它的工作完美...問題是爲什麼?爲什麼多數人似乎依賴於操作秩序?
嗯,我喜歡只讀,我會給其餘的一個旋轉,讓你知道。我不是100%確定你爲什麼提到自動增量鍵。我的樣品根本就沒有。 – user3589700 2015-04-08 00:09:16