I am new to nHibernate. I set up the following one-to-one mapping between the two User and User File tables.
User.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Core.Domain.Model" assembly="Core"> <class name="User" table="Users" dynamic-update="true" lazy="false"> <cache usage="read-write"/> <id name="UserId" column="UserId" type="guid"> </id> <one-to-one name="UserProfile" class="UserProfile"/> </class> </hibernate-mapping>
UserProfile.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Core.Domain.Model" assembly="Core"> <class name="UserProfile" table="UserProfiles" dynamic-update="true" lazy="false"> <cache usage="read-write"/> <id name="UserProfileId" column="UserProfileId" type="int"> <generator class="native"/> </id> <property name="Description" length="100"/> <many-to-one name="User" unique="true" column="UserId"/> </class> </hibernate-mapping>
My POCOs for the above mappings:
public class User { public virtual Guid UserId { get; set; } public virtual UserProfile UserProfile { get; set; } } public class UserProfile { public virtual int UserProfileId { get; set; } public virtual User User { get; set; } }
Now, when I try to save my User object, I get an exception: " The specified key is not in the dictionary in the following line:
using (ISession session = SessionFactory.OpenSession())
Does anyone know what could be happening here?
source share