c# - 批量更新从更新中返回了意外的行数;实际行数 : 0; expected: 1

标签 c# sql database nhibernate orm

我很难弄清楚 NH 异常:

Batch update returned unexpected row count from update; actual row count: 0; expected: 1

我的 DAL 代码:

 public T Save(T item)
        {
            using (ISession session = NHibernateHelper.GetSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(item);

                    transaction.Commit();

                    return item;
                }
            }
        }

我的 log4net 文件:

command 0:UPDATE Metadata_FriendDetails SET UserId = @p0, Email = @p1, Name = @p2 WHERE FriendId = @p3;@p0 = a358ab9d-d481-4bdd-8cb2-18ddc8898c70 [Type: Guid (0)], @p1 = '1@hotmail.com' [Type: String (4000)], @p2 = 'myFriend' [Type: String (4000)], @p3 = 2ea35658-edb1-43e3-b848-e1915d1042df [Type: Guid (0)]

2011-12-02 13:06:49,750 [Agent: adapter run thread for test 'SaveFriendDetails_Test' with id '17016e48-1ff4-4dea-8536-6aa3b24e5fb7'] DEBUG NHibernate.AdoNet.AbstractBatcher - Closed IDbCommand, open IDbCommands: 0 2011-12-02 13:06:49,751 [Agent: adapter run thread for test 'SaveFriendDetails_Test' with id '17016e48-1ff4-4dea-8536-6aa3b24e5fb7'] ERROR NHibernate.Event.Default.AbstractFlushingEventListener - Could not synchronize database state with session NHibernate.StaleStateException: Batch update returned unexpected row count from update; actual row count: 0; expected: 1

有人看到问题了吗?

TIA

最佳答案

问题是在保存时我不应该提供 id 值,而在更新时我必须提供它。

关于c# - 批量更新从更新中返回了意外的行数;实际行数 : 0; expected: 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8350855/

相关文章:

sql - 通过一次选择查找组中的最大值

sql - Doctrine 查询: confusing addWhere, andWhere,orWhere

ruby-on-rails - 基于客户端的网站的最佳数据库策略(Ruby on Rails)

c# - 如何优化此代码以创建 TIFF 文件和/或我应该考虑使用哪些替代库来提高性能?

c# - 尝试对没有所有元素的数组列表进行排序

c# - 由于某种原因,字节乘以字节是 int。为什么?无法将类型 'int' 隐式转换为 'byte' 。存在显式转换

php - 在显示屏顶部显示特色产品

c# - 有什么方法可以通过 identityserver3 将自定义状态或上下文从客户端传递到自定义 IdP?

sql - 在系统中创建用户 ID 的最佳实践是什么?

iphone - 在 iphone sdk 中以编程方式创建 sqlite 数据库