/// <summary>
        /// Removes all data from tables provided
        /// </summary>
        public void Clear(string[] TableNames)
        {
            Clr clr = new Clr();

            Db.Transact(() => {
                foreach (string table in TableNames) {
                    string name = clr.EscapeTableName(table);
                    string sql = string.Format("DELETE FROM {0}", name);

                    Db.SlowSQL(sql);
                }
            });
        }
        public ExcelPackage Export(string[] TableNames)
        {
            Dictionary<ulong, TableContainer> dictionary = new Dictionary<ulong, TableContainer>();
            List<ulong> selectedObjects = new List<ulong>();

            foreach (string name in TableNames) {
                ClrClass meta = Db.SQL<ClrClass>("SELECT t FROM Starcounter.Metadata.ClrClass t WHERE t.FullName = ?", name).First;

                if (meta == null) {
                    throw new ArgumentException(string.Format("Invalid table name: {0}!", name));
                }

                TableContainer table;

                if (!dictionary.TryGetValue(meta.GetObjectNo(), out table)) {
                    table = new TableContainer();
                    dictionary.Add(meta.GetObjectNo(), table);
                }

                table.Meta = meta;

                if (meta.Inherits == null) {
                    continue;
                }

                TableContainer parent;

                if (!dictionary.TryGetValue(meta.Inherits.GetObjectNo(), out parent)) {
                    parent = new TableContainer();
                    dictionary.Add(meta.Inherits.GetObjectNo(), parent);
                }

                table.Parent = parent;
                parent.Children.Add(table);
            }

            Clr clr = new Clr();
            ExcelPackage package = new ExcelPackage();
            ExcelWorksheet sheet = package.Workbook.Worksheets.Add("Legend");
            int row = 1;

            sheet.Cells[row, 1].Value = "Table";
            sheet.Cells[row, 2].Value = "Objects";

            while (dictionary.Any()) {
                var leaves = dictionary.Where(x => x.Value.Children.Count == 0).ToList();

                foreach (var container in leaves.ToList()) {
                    string tableName = clr.EscapeTableName(container.Value.Meta.FullName);
                    string sql = string.Format("SELECT o FROM {0} o", tableName);
                    QueryResultRows<object> objects = Db.SQL(sql);

                    foreach (object obj in objects) {
                        if (selectedObjects.Contains(obj.GetObjectNo())) {
                            continue;
                        }

                        selectedObjects.Add(obj.GetObjectNo());
                        container.Value.Objects.Add(obj);
                    }
                }

                foreach (var leaf in leaves) {
                    row++;
                    sheet.Cells[row, 1].Value = leaf.Value.Meta.FullName;
                    sheet.Cells[row, 2].Value = leaf.Value.Objects.Count;

                    ExportTable(package, leaf.Value);

                    if (leaf.Value.Parent != null) {
                        leaf.Value.Parent.Children.Remove(leaf.Value);
                    }

                    dictionary.Remove(leaf.Value.Meta.GetObjectNo());
                }
            }

            sheet.Cells.AutoFitColumns();

            return package;
        }