This is a mirror of official site: http://jasper-net.blogspot.com/

NHibernate Pitfalls: Merge

| Wednesday, September 21, 2011
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.

Sometimes there may be the need to store a loaded entity in a place that outlives the session that retrieved it.

Later on, you need to associate this entity with a new session, in order to continue using it; for this, you tipically use the Merge method. When you do this, however, you must use a new reference to the entity returned by this method:

Order order = HttpContext.Current.Session["order"] as Order;
Order savedOrder = session.Merge<Order>(order);
savedOrder.Customer = session.Load<Customer>(Int32.Parse(this.customerDropDownList.SelectedValue));


Read more: Development With A Dot
QR: nhibernate-pitfalls-merge.aspx

Posted via email from Jasper-net

0 comments: