I have a created this model;
namespace gantt.Models
{
public class ganttModels
{
public IList<ganttModel> allGantt { get; set; }
}
public class ganttModel
{
public string projectName { get; set; }
public IEnumerable<ResourcesSet> rescource { get; set; }
}
}
Now my plan is to add items to this model, i have done this in a repository like this;
namespace gantt.Models
{
public class GantDataRepository
{
GantEntities dbContext = new GantEntities();
ganttModels returnModels = new ganttModels();
ganttModel tempganttModel = new ganttModel();
public GantDataRepository()
{
foreach (var item in dbContext.WorkPlans)
{
tempganttModel.projectName = item.Product;
tempganttModel.rescource = item.ResourcesSets;
returnModels.allGantt.Add(tempganttModel); // Here i get the error
}
}
public ganttModels getGant()
{
return returnModels;
}
}
}
The repositor finds the data and add it. As i see it i have instansiate the returnModels already
returnModels.allGanttis never instantiated...null. Interfaces, as well as classes and delegates, are declared as reference types.