What are the differences between HasOne() and References() in nhibernate?
            Asked
            
        
        
            Active
            
        
            Viewed 1.1k times
        
    39
            
            
         
    
    
        Michael Petrotta
        
- 59,888
- 27
- 145
- 179
 
    
    
        Hannoun Yassir
        
- 20,583
- 23
- 77
- 112
1 Answers
48
            HasOne creates a one-to-one mapping between tables for you. References creates a typical relational many-to-one relationship. 
More defined:
- a one-to-one relationship means that when one record exists in one table, it must (or can) have one and at most one record in the other referenced table. Example: User table and Options table (one user has one fixed set of options)
- a many-to-one relationship means that when one records exists in one table, it can have many related records in another table. Example: User table and Purchase table (one user can do many purchases).
Note: where I say table you can replace that safely with class or entity as you wish, when using FluentNH it's easy to use them interchangeably.
This is more precisely explained in this fluentnhibernate wiki article.
 
    
    
        Brad Knowles
        
- 119
- 1
- 1
- 9
 
    
    
        Abel
        
- 56,041
- 24
- 146
- 247