[英]Error when using Merge() in NHibernate: a different object with the same identifier
I'm using FluentNHibernate and when i make post got this error. 我正在使用FluentNHibernate,当我发帖时遇到此错误。
a different object with the same identifier value was already associated with the session
具有相同标识符值的另一个对象已与该会话相关联
That is my Controller: 那就是我的控制器:
private readonly ITicketAppService _ticketAppService;
public TicketController()
{
ITicketAppService ticketAppService = new TicketAppService(new TicketService(new TicketRepository(), new RomaneioCodRepository(), new ParamGerarMZRepository()));
}
public ResponseApi Post(Ticket ticket)
{
var result = new ResponseApi();
try{
//my code goes here
//my code goes here
//my code goes here
_ticketAppService.Add(ticket);
_ticketAppService.Commit();
result.DocsSaved.AddRange(ticket.ROMANEIOs);
}
catch (Exception ex)
{
_ticketAppService.RollBack();
result.Errors.Add(new Erro(ex));
}
return result;
}
And that is my Add on RepositoryBase: 那就是我在RepositoryBase上添加的内容:
public virtual void Add(TEntity obj)
{
try
{
BeginTrasaction();
Db.Merge(obj);
}
catch (Exception ex)
{
Log.ErrorFormat("Erro ao tentar adicionar alterações. Detalhes: {0}", ex);
throw new Exception("Erro ao tentar adicionar registro.", ex);
}
}
All questions as i see sayed for use Merge() cause NHibernate try save one ID from user as is already on session, but i got the same error using Merge(). 我认为要使用Merge()的所有问题都会导致NHibernate尝试从会话中保存用户的一个ID,但是使用Merge()却遇到了相同的错误。 And i'm also using session-per-request.
而且我还在使用每个请求会话。 And i have tried make the same on this documentation .
我已经尝试过在此文档中做同样的事情。 Someone know's how can i fix that?
有人知道我该如何解决?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.