public CustomerViewModel() { using (DatabaseContext databaseContext = new DatabaseContext()) { IEnumerable<Customer> customers = databaseContext.Customers.ToList(); IEnumerable<CustomerVM> customersVM = customers.Select(c => new CustomerVM(c)); Customers = new ObservableCollection<CustomerVM>(customersVM); IEnumerable<RegionVM> regionsVM = databaseContext.Regions.ToList().Select(c => new RegionVM(c)); Regions = new ObservableCollection<RegionVM>(regionsVM); foreach (Customer customer in customers) { databaseContext.Entry(customer).Reference(c => c.Region).Load(); } } }
public QuestionListTemplatesViewModel() { _databaseContext = new DatabaseContext(); IEnumerable<QuestionListTemplate> questionListTemplates = _databaseContext.QuestionListTemplates.ToList(); IEnumerable<QuestionListTemplateVM> questionListTemplatesVM = questionListTemplates.Select(questionListTemplate => new QuestionListTemplateVM(questionListTemplate)); IEnumerable<InspectionTypeVM> inspectionTypes = _databaseContext.InspectionTypes.ToList().Select(inspectionType => new InspectionTypeVM(inspectionType)); QuestionListTemplates = new ObservableCollection<QuestionListTemplateVM>(questionListTemplatesVM); InspectionTypes = new ObservableCollection<InspectionTypeVM>(inspectionTypes); DoAddTemplate = new RelayCommand(AddTemplate); foreach (QuestionListTemplate questionListTemplate in questionListTemplates) { _databaseContext.Entry(questionListTemplate).Reference(qLT => qLT.InspectionType).Load(); } }