I have 2 objects Person and Address, a person has one address.
EDIT: The address already exists, I just want to save the foreign key.
When I do this:
PersonDTO person = new PersonDTO(); person.Age = "Bob"; person.Address = new AddressDTO {Key = 123}; Save(person);
I get this exception:
Cannot insert a NULL value in the Key column, Address table; column does not allow null. INSERT fails. approval completed.
Displaying a fragment of a file from Person
<class name="PersonDTO" table="Person" xmlns="urn:nhibernate-mapping-2.2"> <id name="Key" column="PersonKey" type="Guid"> <generator class="guid" /> </id> <one-to-one name="Address" class="AddressDTOl" /> </class>
I do not understand why this is happening, I give the Address Key value. Is my approach wrong?
source share