I've an issue using one-to-one mapping. I've searched internet and found many solutions but none was satisfying. Most of the examples carry overhead of storing parent instance in child class.
I want to use only parent Id in child class having foreign key constraint relationship but dont want to keep any parent instance in child.
When I try to load the records from database it throws exception "No row with the given identifier exists [AssemblyName.B#d6455522-6c6d-4582-b6fb-5ac5ce9551f6]". But, the record exists in Table "B" properly.
Any solutions for this issue?
The class structure:
class A { public virtual string Id {get;set;} public virtual B _B_ {get;set;} // properties...... }
class B { public virtual string Id {get;set;} // properties...... public virtual string ParentId { get;set;} // class A Id }
The database structure:
CREATE TABLE [A]( [Id] [nvarchar](45) NOT NULL ///.... CONSTRAINT [PK__A__00000000000002C0] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
CREATE TABLE [B]( [Id] [nvarchar](45) NOT NULL, [ParentId] [nvarchar](45) NOT NULL CONSTRAINT [PK__B__0000000000000B7A] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
The mapping:
For Class A:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="A,AssemblyName" table="A" lazy="true"> <id name="Id" column="Id" type="string"> <generator class="assigned"/> </id> <one-to-one name="_B" cascade="all" fetch="join" foreign-key="None" constrained="true" class="B"/> </class> </hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="B,AssemblyName" table="B" lazy="true"> <id name="Id" column="Id" type="string"> <generator class="assigned"/> </id> <property name="_Name" column="Name"/> </class> </hibernate-mapping>
|