如何解决“批量更新从更新中返回意外行数;”的问题实际行数:0;预期:1”问题?
每次我尝试创建一个特定实体时都会得到这个......只是想知道我应该如何找出原因。
我正在使用 Fluent NHibernate 自动映射,因此也许我没有适当地设置约定和/或需要覆盖一个或多个映射文件中的某些内容。我浏览了网络上有关此问题的许多帖子,但很难弄清楚为什么会在我的案例中发生这种情况。
我要保存的对象非常简单。它是一个“Person”对象,引用“Company”实体并具有“Address”实体的集合。 UPDATES 在数据库中已有的现有 Person 对象上工作得很好。
有什么建议吗?
Getting this every time I attempt to CREATE a particular entity ... just want to know how I should go about figuring out the cause.
I'm using Fluent NHibernate auto-mapping so perhaps I haven't set a convention appropriately and/or need to override somethings in one or more mapping files. I've gone thru a number of posts on the web regarding this problem and having a hard time figuring out exactly why it is happening in my case.
The object I'm saving is pretty simple. It is a "Person" object that references a "Company" entity and has a collection of "Address" entities. UPDATES work fine on existing Person objects that are already in the database.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
该错误表示正在执行 SQL INSERT 语句,但 SQL Server 运行后返回的 ROWCOUNT 为 0,而不是预期的 1。
有多种原因,从不正确的映射到关闭行计数的 UPDATE/INSERT 触发器。
最好的办法是分析 SQL 语句并看看会发生什么。为此,请打开 nHibernate sql 日志记录,或使用sql 分析器。一旦你有了 SQL,你可能就会知道原因,如果没有,请尝试手动运行 SQL,看看会发生什么。
另外,我建议您发布您的映射,因为它将帮助人们发现任何问题。
The error means that the SQL INSERT statement is being executed, but the ROWCOUNT being returned by SQL Server after it runs is 0, not 1 as expected.
There are several causes, from incorrect mappings, to UPDATE/INSERT triggers that have rowcount turned off.
Your best beat is to profile the SQL statements and see what happens. To do that either turn on nHibernate sql logging, or use the sql profiler. Once you have the SQL you may know the cause, if not try running the SQL manually and see what happens.
Also I suggest you to post your mapping, as it will help people spot any issues.
当触发器执行影响行计数的额外 DML(数据修改)查询时,可能会发生这种情况。我的解决方案是在触发器顶部添加以下内容:
This can happen when trigger(s) execute additional DML (data modification) queries which affect the row counts. My solution was to add the following at the top of my trigger:
这可能是由于自动增量主键而发生的。为了解决这个问题,不要在数据集中插入自动增量值。插入没有主键的数据。
This may occur because of Auto increment primary key. To solve this problem do not inset auto increment value with data set. Insert data without the primary key.
当使用 INSTEAD OF 触发器定位视图时,几乎不可能获得正确的行数。在深入研究源代码后,我发现您可以创建一个自定义持久器,使 NHibernate 忽略计数检查。
When targeting a view with an INSTEAD OF trigger it can be next to impossible to get the correct row count. After delving a bit into the source I found out that you can make a custom persister which makes NHibernate ignore the count checks.
如果行数大于 1,通常是因为表中存在具有相同 id 的重复行。检查表中是否有重复的记录。删除重复项即可解决该问题。
if you get row count greater than 1 its usually because you have duplicate rows in a table that have same ids. Check your table for duplicated records. Deleting duplicates will fix it.