2012-04-13 4 views
0

데이터베이스에 새 사용자를 저장하려고하면 문제가 있습니다. 내 코드 :SaveOrUpdate()에서 Collection을 null로 설정할 수 없습니다.

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. session.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; } 
} 
+0

'User' 클래스를 게시 해주십시오. –

+0

@Rory McCrossan 업데이트 – LuckSound

+0

재사용 대신 새로운 사용자를 어떻게 만듭니 까? – abatishchev

답변

3

어쩌면 클래스 "사용자"예를 들어 일부 참조 있습니다 :

class User 
{ 
    public User 
    { 
    T = new List<T>(); 
    } 
    IList<T> T; 
} 
+0

정말 고마워요.) – LuckSound

1
: constractor으로이 필드를 초기화

class User 
{ 
    IList<T> T; 
} 

시도를

제 경우에는 콜렉션 initzialize를 Hashset에서 Ha로 바꿀 필요가있었습니다. 헛간.

관련 문제