# 持久性框架中的參照標識

public class Order
{
public int OrderId{get;set;}
public EntityCollection Items{get;}
}

public class LineItem
{
public Order Order{ get;set;}
}


var order = Order.FindById( 1000 );


object.ReferenceEquals( order, order.Items[ 0 ].Order );


## 最佳答案

NHibernate works this way within a single session (Unit Of Work). There are ways to make it work this way beyond a single session by using the NHibernate second level cache. A great explanation of this can be found here First And Second Level Caching In NHibernate