When I am trying to give value to a variable which is (should be) an object of another class DataContext through constructor it's always a null and I get a NullReferenceException. When I am trying to this by set accessor everything works fine.
public class DataRepository
{
private DataContext data;
private AnyFiller currentFiller;
public AnyFiller CurrentFiller
{
get
{
return currentFiller;
}
set
{
this.currentFiller = value;
}
}
public DataContext Data { get; set; }
public DataRepository()
{
this.data = new DataContext();
}
public DataRepository(DataContext data)
{
this.data = data;
}
neither one of constructors works fine, but as I said before, it's working when I am doing something like this:
DataContext cont = new DataContext();
DataRepository data = new DataRepository();
data.Data = cont;
Could anybody tell me what am I doing wrong?