2009-04-13 45 views
1

我知道这个问题重复一次。 但是,没有人能够简要回答,以便正确回答。 当我尝试使用GUID向我提供表中的记录时,我得到Nhibernate错误“无给定标识符的行发现错误”。 我正在使用Nhibernate加载函数加载具有唯一标识符(GUID)的记录,但是如果记录不存在,它会发出异常。 我是否缺少hbm.xml文件中的一些属性?Nhibernate错误:没有给定标识符的行发现错误

回答

3

documentation

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

如果您想查询特定记录,并没有异常,使用实际的查询或Get()方法。

而且从文档:

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()并检查结果为空。

+0

非常感谢:) – zchpit 2016-07-14 09:40:12