当我尝试将新用户保存在数据库中时,我遇到了问题。我的代码:
if (!user.ValidateUser(username, password))
{
using (var session = NHibernateHelper.OpenSession())
{
User u = new User();
u.Name = username;
u.Email = string.Empty;
u.Password = "123456";
using (var transact = session.Transaction)
{
session.SaveOrUpdate(u); // I have an exception in this line
transact.Commit();
}
}
}
错误:
集合不能为空。参数名称:c
如何在数据库中保存新用户?
PSsession.Save(user1);
也给我这个例外。
更新:用户类
public partial class User
{
public User()
{
this.CurrentTestings = new HashSet<CurrentTesting>();
this.ResultsSet = new HashSet<ResultTesting>();
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Password { get; set; }
public virtual string Email { get; set; }
public virtual ICollection<CurrentTesting> CurrentTestings { get; set; }
public virtual ICollection<ResultTesting> ResultsSet { get; set; }
}