Nhibernate错误:找不到具有给定标识符的行错误 [英] Nhibernate error: NO row with given identifier found error

查看:84
本文介绍了Nhibernate错误:找不到具有给定标识符的行错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题是重复的. 但是没有人能够回答得足够短以正确回答. 当我尝试使用GUID给我表中的记录时,我收到Nhibernate错误未找到给定identiifer的行". 我正在使用Nhibernate加载功能来加载具有唯一标识符(GUID)的记录,但是如果该记录不存在,则会给出异常. 我是否在hbm.xml文件中缺少某些属性?

I know that this question is repeated one. But no one could answer briefly enough to answer corrctly. I am getting Nhibernate error " No row with given identiifer found error" when im trying to use the guid to give me the record from the table. I am using Nhibernate load function to load the record with the unique identifier(GUID) but if the record is not there it is giving exception. Am I missing some property in hbm.xml file?

推荐答案

来自

请注意,如果没有匹配的数据库行,Load()将引发不可恢复的异常.

Note that Load() will throw an unrecoverable exception if there is no matching database row.

如果要查询特定记录且没有异常,请使用实际查询或Get()方法.

If you want to query for a particular record and not have an exception, use an actual query or the Get() method.

也来自文档:

如果不确定是否存在匹配的行,则应使用Get()方法,该方法会立即访问数据库,如果没有匹配的行,则返回null.

If you are not certain that a matching row exists, you should use the Get() method, which hits the database immediately and returns null if there is no matching row.

因此使用Get()并检查结果是否为空.

So use Get() and check the result for null.

这篇关于Nhibernate错误:找不到具有给定标识符的行错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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