UpdateWithChildren と InsertOrReplaceWithChildren を混同しました。
UpdateWithChildren では動作しませんが、InsertOrReplaceWithChildren では動作します。
だから私はデータベースを削除してからInsertOrReplaceWithChildrenを適用し
ましたが、問題はIDがAutoIncrementであり、IDが追加され続けることです。
アドバイスをいただけますか?
ありがとう。
public class WeekHistory {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public DayOfWeek DayOfWeek { get; set; }
public int NoOfDays { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<DayHistory> DayHistories { get; set; } }
public class DayHistory {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int Hour { get; set; }
public Action Action { get; set; }
public TimeSpan Duration { get; set; }
[ForeignKey(typeof(WeekHistory))]
public int WeekId { get; set; }
[ManyToOne] // Many to one relationship with WeekHistory
public WeekHistory WeekHistory { get; set; }}
List<DayHistory> newMonday = new List<DayHistory>()
{
new DayHistory() {Hour = 1, Action = Action.Known, Duration = new TimeSpan(0,20,0)},
new DayHistory() {Hour = 1, Action = Action.Unknown, Duration = new TimeSpan(0,40,0)},
new DayHistory() {Hour = 2, Action = Action.Known, Duration = new TimeSpan(0,40,0)},
new DayHistory() {Hour = 2, Action = Action.Unknown, Duration = new TimeSpan(0,20,0)},
new DayHistory() {Hour = 3, Action = Action.Known, Duration = new TimeSpan(0,50,0)},
new DayHistory() {Hour = 3, Action = Action.Unknown, Duration = new TimeSpan(0,10,0)}
};
var mondayHistory = dbConn.GetWithChildren<WeekHistory>(1, true);
//delete the db, instead of the UpdateWithChildren
dbConn.DeleteAll(mondayHistory.DayHistories);
mondayHistory.DayHistories = newMonday;
mondayHistory.NoOfDays += 1;
//it won't update the child
//dbConn.UpdateWithChildren(mondayHistory);
//apply new db with children
dbConn.InsertOrReplaceWithChildren(mondayHistory);