hmf_09 2015-03-20 02:44 采纳率: 0%
浏览 1860

NHibernate 保存实体类时无法转换类型

求NHibernate会的请教!
实体类:Userinfo 和 Userinfo.hbm.xml是用codesmith生成的。userinfo属性如下:
protected Guid _id;
protected string _userName;
protected string _password;
protected string _email;
protected int _state = 0 ;
protected string _passwordQuestion;
protected string _passwordAnswer;
protected string _nick;
protected string _realName;
protected string _images;
protected string _backgroundImage;
protected bool _sex;
protected string _mobilePhone;
protected string _address;
protected DateTime _birthday;
protected string _loastLoginIP;
protected DateTime _regTime;
protected int _isDel;
protected DateTime _beginTime = DateTime.Now ;
protected DateTime _updateTime;
protected UserRole _userRole;
protected IList _newsCommentsReplies;
protected IList _publishNewses;
protected IList _newsCommentses;
protected IList _userFavorClasses;

    我写个userdao 保存实体类 userinfo,代码如下:
            ICriteria criteria = _session.CreateCriteria(typeof(UserRole));
            userInfo.UserRole = (UserRole)criteria.List<UserRole>()[0];
            _session.Save(userInfo);
            _session.Flush();
    Save的时候抛出异常:
    无法将类型为“System.Collections.ArrayList”的对象强制转换为类型“Syste    m.Collections.Generic.IEnumerable`1[System.Object]”

    估计是上面实体类的属性与保存时映射的类型不搭配。但都是工具生成的,不知道要怎么改。求解!!
  • 写回答

1条回答 默认 最新

  • hmf_09 2015-03-20 04:01
    关注

    实体类生成的问题!使用codesmith的nhibernate模版的格式有问题,或者是不匹配新版本的NHbernate 4. 结束。

    评论

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名