问题描述
- 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]” 估计是上面实体类的属性与保存时映射的类型不搭配。但都是工具生成的,不知道要怎么改。求解!!
解决方案
实体类生成的问题!使用codesmith的nhibernate模版的格式有问题,或者是不匹配新版本的NHbernate 4. 结束。
时间: 2024-10-23 07:17:57