Thanks again for your reply.
In your code example you only set up one side of the relationship - which i asked about earlier and was told that I need to set up both sides.
This will make it fire a unnessecary SQL Select when the AddUser() method on country is called - setting up both sides in a relationship
Code:
User user = session.Get<User>(111);
Country country = session.Load<Country>(123);
user.Country = country; // Set up primary side
country.AddUser(user); // Set up inverse side - will make it fire a SQL Select immediatly when the method is called on the proxy
session.Save(user);
If i only set the primary side like in your code example (the side which contains the foreign key - in my example the User object) then it works fine and no extra SQL Select is fired. But then i dont set both side of the realtionship.
This works like in your example - but only sets up one side of the relationship
Code:
User user = session.Get<User>(111);
user.Country = session.Load<Country>(123); // Set up primary side
session.Save(user);
Is it only necessary to set up both side of the relationship if both objects are queryed (materialized) ? or when is it needed (i am even more confused now as it was what i tried to ask in the first post) :) ?
In case it is only needed to set up both side of the relationship when the object being added is already queryed / materialized, then how can i check if the object is already queryed (without it being queryed if it isnt) and set up the relationship ?
The reason i am concerned about the "Selects" is because I am going to have some tables with many columns (some with large texts), and i dont want to transfer the data every time when it is not needed.
Also, i am new to NHibernate soo i am pretty sure i must be doing something wrong, when i cant find out to make something this simple work :) , and I will like to learn how to use Nhibernate correctly.