Having problems with dual relationships between entities

Jul 27, 2010 at 10:12 PM
Edited Jul 27, 2010 at 10:18 PM

I have an issue with a section of my model that I just can't get around. It could be a bug, or it could be me...

Consider the relationships circled in this example:

 The following code fails when attempting to relate a Client to a Vendor:

// get the client
var subdomain = new SubDomain( );
subdomain.AddSelectCommand( new ClientSelectByPks( clientId ) );
subdomain.RunSelectCommands( );
ClientCollection cc = subdomain.GetCollection<ClientCollection>( );
var client = cc[ 0 ];

// create a new organization (a type of party)
OrganizationCollection pc = new OrganizationCollection( );
subdomain = pc.SubDomain;
Organization org = pc.NewItem( );
org.LegalName = "storyr";
org.PartyType = "Organization";
pc.AddItem( org );

// create a new vendor (a type of role)
VendorCollection vc = subdomain.GetCollection<VendorCollection>( );
Vendor vendor = vc.NewItem( );
vendor.TaxId = "9-00000000";
vendor.RoleType = "Vendor";
vendor.PartyItem = org;
vc.AddItem( vendor );

// relate the vendor to the last added client
RoleRelationshipCollection rrc = subdomain.GetCollection<RoleRelationshipCollection>( );
RoleRelationship roleRel = rrc.NewItem( );
roleRel.TargetRoleRoleItem = client;
roleRel.SourceRoleRoleItem = vendor; //<<<--FAILS HERE
roleRel.RelationshipType = "Customer";
rrc.AddItem( roleRel );

subdomain.Persist( );

 


The runtime error is:

System.Data.InvalidConstraintException was unhandled
  Message=SetParentRow requires a child row whose Table is VendorCollection, but the specified row's Table is ClientCollection.
  Source=System.Data
 
There are a number of other issues too, such as not being able to walk from Client to RoleRelationship to Vendor...
Coordinator
Jul 28, 2010 at 1:41 AM
This is a very interesting issue. It is also very complicated. Please send your model or better yet the project to me privately and I will look at it (chrisd@nhydrate.org). I would like to investigate walking the relationships as well. I know I probably need data to make all this happen. If you can send the database and code it would be most helpful. I know you may have some privacy policy or some such thing so any information would be useful. Obviously code is the most helpful for me.
Coordinator
Jul 28, 2010 at 1:47 AM
Also your CodePlex settings do not allow contact. If I could contact you directly we might be able to address this issue quicker.
Jul 28, 2010 at 2:00 AM
codetools wrote:
This is a very interesting issue. It is also very complicated. Please send your model or better yet the project to me privately and I will look at it (chrisd@nhydrate.org). I would like to investigate walking the relationships as well. I know I probably need data to make all this happen. If you can send the database and code it would be most helpful. I know you may have some privacy policy or some such thing so any information would be useful. Obviously code is the most helpful for me.

 Thanks! I've forwarded to you a solution that illustrates the problem.  I've also changed my contact options...

Coordinator
Jul 29, 2010 at 2:09 PM

I have your project and it is a complex issue. This will take a while. I am working with another person on this too. It will probably be next week before I know anything.

Jul 30, 2010 at 12:43 AM

Thanks. I have a workaround, but it persists twice - in two different transactions.   Let me know if I can be of any assistance...

Sep 1, 2010 at 11:50 PM

Checking in to see if there's any progress with this issue.  This error is really starting to slow things down, as we have to resort to going around nHydrate to maintain these relationships.  Thanks...