With our current persistence framework properties on a child entity that point to it's parent always point to the same instance. For example, given the following entity classes
public class Order
{
public int OrderId{get;set;}
public EntityCollection<LineItem> Items{get;}
}
public class LineItem
{
public Order Order{ get;set;}
}
We can load an order from the database like this:
var order = Order.FindById( 1000 );
Now here's the key to my question the following is true for our current framework
object.ReferenceEquals( order, order.Items[ 0 ].Order );
That is, the Order property on the line item points to the exact same instance of the order object in memory when accessed through the Items property.
I'm kinda tired of maintaining our entity tools and want to switch to NHibernate or another persistence framework. My question then is, does the lazy loading features of NHibernate work the same way or will it load a new instance of the Order object for each line item?