NHibernate-“不存在具有给定标识符的行"但它在那里 [英] NHibernate - "No row with the given identifier exists" but it is there

查看:84
本文介绍了NHibernate-“不存在具有给定标识符的行"但它在那里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NHibernate,当我使用Session的Get方法时,会出现此错误.

I am using NHibernate and this error appears when I use Get method of Session.

这是我的代码:

public T GetById(object id)
    {
        T entity;
        entity = (T)ReportHttpModule.CurrentSession.Get(typeof(T), id);
        return entity;
    }

请注意,在调用该方法之前使用CreateCriteria(T)时,不会出现此错误!

note that I don't get this error when use CreateCriteria(T) before calling that method!

推荐答案

我已经找到了解决方案.很奇怪,但这是映射文件中的问题.我的其中一列在映射文件中有not-null="true",但在数据库中不能为空!

I've found the solution. It is weird but it was a problem in mapping file. One of my columns had not-null="true" in mapping file but in database was not nullable!

这篇关于NHibernate-“不存在具有给定标识符的行"但它在那里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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