Inheritance question : parent has 1:M relationships

Mar 22, 2010 at 9:10 PM

 

I hit this problem in my project and recreated it in a new test project.  I have 3 tables in the test project, which I created through nhydrate and fired off at a blank database:

Parent
-------- 
ParentId  <-- PK, identity
ParentProperty

Child  <-- Has parent set as "Parent" in the nhydrate.wsgen
--------
ParentId  <-- PK/FK, non-identity
ChildProperty 

ParentsThings  <-- many to one relationship with Parent
---------------- 
ParentsThingsId  <-- PK
ParentId  <-- FK
Things

 

Then populated the tables with some data and set up a simple test:

 

Child foo = Child.SelectUsingPK(1);

Assert.IsNotNull(foo);
Assert.IsTrue(foo.Childproperty.Length>0);
Assert.IsTrue(foo.Parentproperty.Length>0);
Assert.IsTrue(foo.ParentsthingsList.Count==2);

The first 3 assertions succeed, so the inheritance appears to be working.  However, the 4th assertion fails because the ParentsThingsList is never getting populated.  To make things worse, once I turned on inheritance, I lost the ability to access the parent table via foo.ParentItem or something similar, so I have no way of getting to the tables that have relationships with the parent.

I'm crossing my fingers that I'm just doing something wrong.  Any ideas?

 

Mar 22, 2010 at 11:03 PM

To add to what greg said, we also tried

Parent bar = Parent.SelectUsingPK(1);

Assert.IsNotNull(foo);
Assert.IsTrue(bar.ParentsthingsList.Count==2);

Which passed. So that parent to parentThingList relationship worked. But the one from the Child to ParentThingList didn't.

 

 

Coordinator
Mar 23, 2010 at 2:27 PM

First off there is no ParentItem from a child because it is the parent. They are the same object. You should see all child and parent properties on that object. That said please send your model/sample project to chrisd@nhydrate.org.