I'm trying to update data in two tables that are related via a one to one relationship and keep getting an error when trying to set a property value of the related entity.
In the code below I'm trying to update the fields in BottomBracket and ProductVersion tables for a specific ProductVersionID. Everything works fine until I try and call the property bottomBracket.ProductVersion.ActiveState. When this code is executed an error is thrown saying:
"Object reference not set to an instance of an object."
What do I need to do to update fields in two tables with a one to one relationship?
int productVersionID = Convert.ToInt32(e.Item.Cells[1].Text);
BottomBracketEntity bottomBracket = new BottomBracketEntity( this.productID, productVersionID );
bottomBracket.IsNew = false;
bottomBracket.ProductVersion.ActiveState = ((TextBox)e.Item.FindControl("activeState")).Text;
bottomBracket.SpindleLength = Convert.ToDecimal( ((TextBox)e.Item.FindControl("spindleLength")).Text );
bottomBracket.SpindleSplines = Convert.ToDecimal( ((TextBox)e.Item.FindControl("spindleSplines")).Text );
bottomBracket.Width = Convert.ToDecimal( ((TextBox)e.Item.FindControl("width")).Text );
bottomBracket.WidthMax = Convert.ToDecimal( ((TextBox)e.Item.FindControl("widthMax")).Text );
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.SaveEntity( bottomBracket );