功能NHibernate新手:行被更新或者被另一个事务删除 [英] Fluent NHibernate Newbie: Row was updated or deleted by another transaction

查看:683
本文介绍了功能NHibernate新手:行被更新或者被另一个事务删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用流利的NHibernate的构建出一个数据库的早期阶段。我在ASP.NET MVC 3执行单元的工作模式,让NHibernate的更新我的数据库架构我。要插入/更新我初始数据,我有一个数据库控制器,试图将<$ C $的更新行动C> SaveOrUpdate(...) A 用户实体(管理员用户)到用户表。

I'm in the early stages of building out a database with Fluent NHibernate. I implemented a unit-of-work pattern in ASP.NET MVC 3 to let NHibernate update my database schema for me. To insert/update my initial data, I have a Database controller with an Update action that tries to SaveOrUpdate(...) a User entity (the administrator user) into the Users table.

在通过Visual Studio和重新运行我的更新行动来重新填充用户表中手动删除所有的用户记录,我收到以下 NHibernate.StaleObjectStateException 例外:

After manually deleting all user records via Visual Studio and re-running my Update action to repopulate the Users table, I receive the following NHibernate.StaleObjectStateException exception:

Row was updated or deleted by another transaction (or unsaved-value mapping was
incorrect): [Invoicer.Data.Entities.User#3105248d-ca91-4c64-bf8f-9ebb017943b7]

Line 26:        {
Line 27:            if (_transaction.IsActive)
Line 28:                _transaction.Commit();
Line 29:        }

注:保存或更新的用户ID是与上面的值与GUID(3105 ...)

Note: the saved or updated user ID is a Guid with the value above (3105...).

我在做什么错了?

推荐答案

在NHibernate的使用GUID梳方法对我来说指派用户ID(GUID)。手动指定ID被绊倒的映射。我preFER来分配这些ID自己,所以我改变了用户在我的中userMap 类:

Solved with Mapping

NHibernate was assigning User IDs (Guid) for me using the Guid comb method. Manually specifying the ID was tripping up the mapping. I prefer to assign these IDs myself, so I changed the User entity ID mapping to be manually assigned in my UserMap class:

Id(x => x.Id).GeneratedBy.Assigned();

这篇关于功能NHibernate新手:行被更新或者被另一个事务删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆