NHibernate: expelling but still having an exceptional exception for the object

This method is not the best, but the circular link problem continued, so at the last minute he hit it. For some reason, even though I exit the original link order on a detailed object, I still have another connection to the session. Should I use get instead? Or is there a better way to say evict ALL orders with ID = x?

public DetailDTO SaveNewDetailToOrder(DetailDTO detailDTO) { var detailReturn = new DetailDTO(); try { var order = LoadOrderById(detailDTO.OrderId); var previousStatus = issue.CurrentDetailStatus; if (previousStatus != null && detailDTO.Status.Id != previousStatus.Id) { var detail = Mapper.Map<DetailDTO, Detail>(detailDTO); _orderRepository.EvictOrder(detail.DetailOrder); order.Details.Add(detailDTO); order.IsEscalated = false; order.DormantDate = detailDTO.CreatedTime; var orderReturn = SaveOrder(order); ///Error Here if (orderReturn.IsActionSuccessful) { detailReturn = orderReturn.Details.DTOObjects.OrderByDescending(x => x.CreatedTime).First(); SendStatusChangeEmail(orderReturn); } } else { detailReturn = _detailService.SaveDetail(detailDTO); } } catch (Exception ex) { throw ServiceErrorMessage(ex, detailReturn); } return detailReturn ; } 
+2
nhibernate
source share
1 answer

You can access session objects and use what you like

 session.GetSessionImplementation().PersistenceContext.EntityEntries 

but if I were you, I would make sure that I exit the correct object and spend some time debugging. Knowing what's going on is better than finding workarounds

 foreach (var e in session.GetSessionImplementation().PersistenceContext.EntityEntries.Values.OfType<EntityType>().Where(<condition>)) { session.Evict(e); } 
+2
source share

All Articles