nhibernate : a different object with the same identifier value was already associated with the session: 2, of entity:

前端 未结 5 2055
陌清茗
陌清茗 2021-01-01 11:40

I am getting the following error when i tried and save my \"Company\" entity in my mvc application

a different object with the same identifier value was alre

5条回答
  •  [愿得一人]
    2021-01-01 12:05

    I tried @claitonlovatojr's hack, but I couldn't still handle the error.

    All I had to do in my case wasy to replace my ISession.Update(obj) call to ISession.Merge(obj).

    In your repository, change:

    public void Update(Company company)
    {
        using (ITransaction transaction = _session.BeginTransaction())
        {
            //_session.Update(company);
            _session.Merge(company); // <-- this
            transaction.Commit();
        }
    }
    

    Also, for more information see this answer.

提交回复
热议问题