private void LoadAndCreateCommands() { if (tableDefinition.Commands == null) { return; } foreach (var command in tableDefinition.Commands) { var cmd = commandService.FindCommand(command.CommandId); if (cmd != null) { Commands.Add(new TableCommandViewModel(cmd, new AsyncAutoCommand(() => { return(messageBoxService.WrapError(() => WrapBulkEdit( () => WrapBlockingTask( () => cmd.Process(command, new DatabaseTableData(tableDefinition, Entities), this) ), cmd.Name))); }))); } else { var cmdPerKey = commandService.FindPerKeyCommand(command.CommandId); if (cmdPerKey == null) { throw new Exception("Command " + command.CommandId + " not found!"); } Commands.Add(new TableCommandViewModel(cmdPerKey, new AsyncAutoCommand(() => { return(messageBoxService.WrapError(() => WrapBulkEdit( () => WrapBlockingTask(() => cmdPerKey.Process(command, new DatabaseTableData(tableDefinition, Entities), GenerateKeys().ToList(), this)) , cmdPerKey.Name))); }))); } } }