UpdateWithChildren doesn't update recursively

Issue #29 wontfix
Jeremy Kolb created an issue

I have the following:

public class TaskDailyProgress
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }

        [ForeignKey(typeof(OperationalTask))]
        public int OperationalTaskId { get; set; }

        [ManyToOne]
        public OperationalTask OperationalTask { get; set; }

        [Indexed]
        public DateTime Date { get; set; }

        [OneToMany(CascadeOperations = CascadeOperation.All)]
        public List<TaskDailyProgressPersonnel> PersonnelProgress { get; set; }

        [OneToMany(CascadeOperations = CascadeOperation.All)]
        public List<TaskDailyProgressEquipment> EquipmentProgress { get; set; }
    }

    public abstract class TaskDailyProgressLinesBase
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }

        [ForeignKey(typeof (TaskDailyProgress))]
        public int TaskDailyProgressId { get; set; }

        [ManyToOne]
        public TaskDailyProgress TaskDailyProgress { get; set; }
    }

    public class TaskDailyProgressPersonnel : TaskDailyProgressLinesBase
    {
        [OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
        public Personnel Personnel { get; set; }

        [ForeignKey(typeof(Personnel))]
        public int PersonnelId { get; set; }

        public double Hours { get; set; }
    }

    public class TaskDailyProgressEquipment : TaskDailyProgressLinesBase
    {
        [OneToOne(CascadeOperations = CascadeOperation.CascadeRead)]
        public Equipment Equipment { get; set; }

        [ForeignKey(typeof(Equipment))]
        public int EquipmentId { get; set; }

        public double EngineHoursStart { get; set; }
        public double EngineHoursEnd { get; set; }
    }

My update method looks like:

connection.BeginTransaction();
            try
            {
                if (dailyProgress.Id == 0)
                {
                    connection.InsertWithChildren(dailyProgress, true);
                }
                else
                {
                    connection.UpdateWithChildren(dailyProgress);
                }
            }
            catch
            {
                connection.Rollback();
                throw;
            }
            connection.Commit();

It works great for inserting but for updating it doesn't update Hours or EngineHoursStart/EngineHoursEnd. To do that I have to add the following:

connection.UpdateAll(dailyProgress.PersonnelProgress);
connection.UpdateAll(dailyProgress.EquipmentProgress);

Why doesn't UpdateWithChildren cascade?

Comments (2)

  1. Guillermo GutiƩrrez

    There's no recursive version of UpdateWithChildren on purpose, in fact there's already a convenience method for what you are trying:

    connection.RunInTransaction(() => conn.InsertOrReplaceWithChildren(dailyProgress, true));
    
  2. Guillermo GutiƩrrez

    Closed. There's already an existing method with a more explicit name exposing this functionality.

  3. Log in to comment