public ProductBaseModel GetProductBaseModel(int productBaseId) { if (productBaseId == 0) { return(new ProductBaseModel()); } using (var context = _contextFactory.CreateContext()) { var model = context.ProductBases .AsNoTracking() .Where(p => p.ProductBaseId == productBaseId) .Include(pb => pb.Products).ThenInclude(p => p.Prices) .Include(pb => pb.Products).ThenInclude(p => p.ProductSource) .Include(pb => pb.Products).ThenInclude(p => p.ProductDestination) .Include(pb => pb.ProductVariationsLink).ThenInclude(pvl => pvl.ProductVariation) .Select(p => MappingFactory.MapTo <ProductBaseModel>(p)) .FirstOrDefault(); var priceList = context.PriceLists .AsNoTracking() .Where(pl => pl.Prices.Any(p => p.Product.ProductBaseId == productBaseId)) .Select(pl => MappingFactory.MapTo <PriceListModel>(pl)); model.PriceLists = new ObservableCollection <PriceListModel>(priceList); return(model); } }
public CompanyModel GetCompanyModel(int companyId) { if (companyId == 0) { return(GetNewCompanyModel()); } using (var context = _contextFactory.CreateContext()) { return(context.Companies .AsNoTracking() .Include(c => c.Addresses) .Include(c => c.Contacts) .Include(c => c.CompanyTypesLink).ThenInclude(l => l.CompanyType) .Where(c => c.CompanyId == companyId) //.ProjectBetween<Company, CompanyModel>() .Select(c => MappingFactory.MapTo <CompanyModel>(c)) .FirstOrDefault()); } }