public static List<AllocationJournalViewModel> GetAllocationJournal() { var db = new IstokDoorsDBContext(); db.usp_FillInAllocationJournalBySystem(); var myAllocationJournal = db.AllocationJournals.Include(o=>o.OrderHeader). Where(o => o.OrderHeader.IsCancelled == false).ToList(); var myAllocJournList = new List<AllocationJournalViewModel>(); foreach (var item in myAllocationJournal) { var myModel = new AllocationJournalViewModel(); myModel.OrderId = item.OrderId; myModel.FactoryId = item.FactoryId ?? 0; myModel.OrderedQuantity = item.OrderedQuantity ?? 0; myModel.IsSelectedForPlanning = false; myModel.Customer = item.Customer; myModel.FactoriesForAllocJournal = GetValuesForAllocJournFactoriesDdl(item.FactoryId); myAllocJournList.Add(myModel); } return myAllocJournList; }