I am in the process of testing nHibernate and I want to know if I can do the following.
I have two tables contacts and emails. Theirs a relationship between them. I can create an instance of the contact like so :
Contact newContact = new Contact();
newContact.title = "Mr";
newContact.name = "George";
newContact.surname = "Robinson";
newContact.primaryemailaddress.emailaddress = "Test1111@test.com";
newContact.primaryemailaddress.whenchanged = System.DateTime.Now;
newContact.primaryemailaddress.whencreated = System.DateTime.Now;
newContact.birthdate = DateTime.Now;
newContact.whenchanged = DateTime.Now;
newContact.whencreated = DateTime.Now;
The primaryemailaddress lines 4,5,6 reference the emails table. However when i debug this i get error on those lines 3,4,5 with the old classic 'Object reference not set to an instance of an object. ' Now I know why, its trying to pass values into my properties when the class (emails) for these properties has not been instantiated. It would be really cool if i could create one object and be able to pass values into its child tables as well (all in the same object). I thought this would be a key feature of nhibernate but I'm new and havent got a clue on how to implement the above.
ANy help greatly appreciated.
|