Hi - this is probably more to do with my lack of understanding about C# than anything else .....
I have the following classes:
public class Parent
{
public Parent()
{
Calculated = new Calculator(this);
}
public Child Child { get; set; }
public Calculator Calculated { get; private set; }
}
public class Child
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Calculator
{
public Calculator(Parent parent)
{
Parent = parent;
}
public Parent Parent { get; private set; }
public string Name
{
get { return Parent.Child.FirstName + " " + Parent.Child.LastName; }
}
}
I can serialize and deserialize Parent correctly by making direct calls to JsonConvert.SerializeObject.
I can also map Parent using Automapper.
However Raven will not SaveChanges, reporting that Parent.Calculated.Name is null. If I expose Calculator.Parent as a public property I get " Self referencing loop detected". If I make Parent (_parent) a private field of Calculator, it is not getting initialized at the moment that SaveChanges is called, but no Self referencing loop exception.
Is there some way of getting around this? I can force the initialization of Calculator by adding an Init method to both Parent and Calculator (which is what I'm doing at the moment) - but this is very smelly, i.e. in Calculator:
public void Init(Parent parent){
this._parent = parent;
}
Many thanks in advance
Jeremy