public int GetDueTimeByOrder(IDemandToProvider demand) { if (demand.GetType() == typeof(DemandOrderPart)) { demand = Demands.OfType <DemandOrderPart>().Include(a => a.OrderPart).ThenInclude(b => b.Order).ToList().Single(a => a.Id == demand.Id); return(((DemandOrderPart)demand).OrderPart.Order.DueTime); } if (demand.GetType() == typeof(DemandStock)) { return(int.MaxValue); } if (demand.GetType() != typeof(DemandProductionOrderBom)) { return(int.MaxValue); } { demand = Demands.AsNoTracking().OfType <DemandProductionOrderBom>() .Include(a => a.ProductionOrderBom) .ThenInclude(b => b.ProductionOrderParent) .Single(c => c.Id == demand.Id); return(((DemandProductionOrderBom)demand).ProductionOrderBom.ProductionOrderParent.Duetime); } }