private void OnMultyAddCategoryExecute(int?CategoryKey) { MultySelectEntityesDialog dlg = new MultySelectEntityesDialog(); var items = _repository.GetEntitiesByCondition(x => x.DriveId == DriveId && x.EntityType == 2); ObservableCollection <ArchiveEntityLookupDto> lookup = new ObservableCollection <ArchiveEntityLookupDto>(); foreach (var item in items) { lookup.Add(new ArchiveEntityLookupDto() { ArchiveEntityKey = item.ArchiveEntityKey, EntityPath = item.EntityPath, prSel = false, Title = item.Title }); } dlg.DataContext = new MultySeltEntityeecsViewModel(lookup); if (dlg.ShowDialog() == true) { var category = _categoryRepository.GetCategoryByKey(CategoryKey); var result = dlg.DataContext as MultySeltEntityeecsViewModel; var entities = new List <int>(); foreach (var item in result.Items.Where(x => x.prSel == true)) { entities.Add(item.ArchiveEntityKey); } _categoryRepository.AddCategoryToEntities(category, entities); } }