public ProductDefectionsVM(ProductVM product, AccessType access):base(access) { UnitOfWork = new SoheilEdmContext(); CurrentProduct = product; ProductDataService = new ProductDataService(UnitOfWork); ProductDataService.DefectionAdded += OnDefectionAdded; ProductDataService.DefectionRemoved += OnDefectionRemoved; DefectionDataService = new DefectionDataService(UnitOfWork); ProductDefectionDataService = new ProductDefectionDataService(UnitOfWork); var selectedVms = new ObservableCollection<ProductDefectionVM>(); foreach (var productDefection in ProductDataService.GetDefections(product.Id)) { selectedVms.Add(new ProductDefectionVM(productDefection, Access, ProductDefectionDataService, RelationDirection.Straight)); } SelectedItems = new ListCollectionView(selectedVms); var allVms = new ObservableCollection<DefectionVM>(); foreach (var defection in DefectionDataService.GetActives(SoheilEntityType.Products, CurrentProduct.Id)) { allVms.Add(new DefectionVM(defection, Access, DefectionDataService)); } AllItems = new ListCollectionView(allVms); IncludeCommand = new Command(Include, CanInclude); ExcludeCommand = new Command(Exclude, CanExclude); IncludeRangeCommand = new Command(IncludeRange, CanIncludeRange); ExcludeRangeCommand = new Command(ExcludeRange, CanExcludeRange); }