コードの壁を許してください、しかし、私は舞台を設定する必要があります....
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; }
}
これらのクラスが与えられた場合、関係を維持しながら学生、スタッフ、保護者をデータベースに挿入するにはどうすればよいですか? サーバーは入力された Student レコードを返すことに注意してください。これが私の出発点です。
私は試してみconn.InsertOrReplaceWithChidlren(student);
ました...学生、学生スタッフ、学生保護者のレコードを挿入しましたが、実際のスタッフや保護者は挿入しませんでした。スタッフ、保護者、教師が挿入されたOddlyを試し
conn.InsertOrReplaceWithChildren(student);
conn.InsertOrReplaceWithChildren(student.Teachers);
conn.InsertOrReplaceWithChildren(student.Guardians);
ましたが、どちらの交点テーブルにもデータがありませんでした...
--更新--- 試し
conn.InsertOrReplaceWithChildren(student.Teachers);
conn.InsertOrReplaceWithChildren(student.Guardians);
conn.InsertOrReplaceWithChildren(student);
てみたところ、完全に機能しました...問題はなぜですか? 多対多が操作順序に依存しているように見えるのはなぜですか?