internal static Expression <Func <LotProductionResults, ProductionAdditiveInputs> > SelectAdditiveInputs(ILotUnitOfWork lotUnitOfWork) { var lotKey = LotProjectors.SelectLotKey <LotProductionResults>(); var lotProduct = ProductProjectors.SelectProduct(); var additiveLots = LotProjectors.SelectAdditiveLot(lotUnitOfWork); var additiveProduct = ProductProjectors.SelectAdditiveProduct(); var additiveLotKey = LotProjectors.SelectLotKey <AdditiveLot>(); return(r => new ProductionAdditiveInputs { ProductionDate = r.ProductionBegin, LotKeyReturn = lotKey.Invoke(r), LotProduct = lotProduct.Invoke(r.Production.ResultingChileLot.ChileProduct.Product), PickedAdditiveItems = r.Production.PickedInventory.Items.Select(i => new { Item = i, AdditiveLot = additiveLots.Invoke(i.Lot).FirstOrDefault() }) .Where(i => i.AdditiveLot != null) .Select(i => new ProductionPickedAdditive { LotKeyReturn = additiveLotKey.Invoke(i.AdditiveLot), TotalPoundsPicked = i.Item.Quantity * i.Item.PackagingProduct.Weight, AdditiveProduct = additiveProduct.Invoke(i.AdditiveLot.AdditiveProduct), UserResultEntered = r.Employee.UserName }) }); }