我尝试在数据库中保存新用户时遇到问题。我的代码:SaveOrUpdate()上收集不能为空
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();
}
}
}
错误:
Collection cannot be null. Parameter name: c
如何保存新的用户数据库?
P.S. session.Save(user1);
也给我这个例外。
更新: User类
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; }
}
请问您可以发布'User'类。 – 2012-04-13 10:01:03
@Rory McCrossan更新 – LuckSound 2012-04-13 10:38:23
你是什么创建一个新的用户而不是重复使用? – abatishchev 2012-04-13 10:42:54