2009-04-13 43 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