Example #1
0
        /// <summary>
        /// Write the necessary Sql statements into the specified SqlStringBuilder
        /// to delete all the records represented by the current collection.
        /// </summary>
        /// <param name="sql"></param>
        public virtual void WriteDelete(SqlStringBuilder sql)
        {
            if (this._values.Count > 0)
            {
                bool deleteIndividually = Parent == null;

                if (!deleteIndividually)
                {
                    if (string.IsNullOrEmpty(ReferencingColumn))
                    {
                        throw new ArgumentNullException("{0}.ReferencingColumn not set", this.GetType().Name);
                    }

                    sql.Delete(Dao.TableName(typeof(T)))
                    .Where(new AssignValue(ReferencingColumn, Parent.IdValue))
                    .Go();
                }

                foreach (Dao d in this)
                {
                    if (d.AutoDeleteChildren)
                    {
                        d.AutoHydrateChildrenOnDelete = AutoHydrateChildrenOnDelete;
                        d.WriteChildDeletes(sql);
                        sql.Go();
                    }

                    if (deleteIndividually)
                    {
                        d.WriteDelete(sql);
                        sql.Go();
                    }
                }
            }
        }
Example #2
0
 public void WriteDelete(SqlStringBuilder sql)
 {
     foreach (L item in this._values)
     {
         if (item.IsNew)
         {
             _values.Remove(item);
         }
         else
         {
             item.WriteDelete(sql);
             sql.Go();
             XrefsByListId[item.IdValue.Value].WriteDelete(sql);
         }
         sql.Go();
     }
 }