这种方法不是我最好的方法,但有一个循环引用问题,所以最后一分钟把它拍打在一起。出于某种原因,即使我驱逐了详细对象上的原始引用顺序,我仍然与会话有另一个关联。我应该使用 get 代替吗?或者更好的是有没有办法说驱逐所有 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 ;
}