This project is read-only.

Subdomain Dilemma

Jun 25, 2010 at 11:00 PM

To make a long story short, I'll cut to the chase:

Consider the following code.  How can I ensure the Client and Person collections are members of the same Subdomain?

Client client = Client.SelectUsingPK( 1 );
Person person = Person.SelectUsingPK( client.PartyId );

The reason, of course, is it need to persist the changes to each in the same transaction.

The longer part of the story is that I'm unable to walk the relationship from Client to Person, as Person is a child table (subtype) of Party, and apparently it's impossible to walk a dependency from a parent to a child.  Here's a sample data model to clarify the example further:  model

Thanks for the help...

Jun 26, 2010 at 7:56 PM

First if you have a relationship defined from Party to Role you should be able to walk from Person->Client, Person->Vendor, Organization->Client, and Organization->Vendor. If this is too broad (based on parent classes) you can define relations directly from Person->Client, etc if you wish. This referential integrity will also manifest itself in the database as well.

Also you can select disparate objects into the same subdomain using the predefined select commands. You can additionally create your own custom ones as well. See the code below to load a USER and a JOB into the same subdomain via two different queries.

SubDomain subdomain = new SubDomain();
subdomain.AddSelectCommand(new JacksonHealthCare.ListingSite.Business.SelectCommands.UserAccountSelectByPks(1));
subdomain.AddSelectCommand(new JacksonHealthCare.ListingSite.Business.SelectCommands.JobSelectByPks(2));
UserAccountCollection userAccountCollection = subdomain.GetCollection<UserAccountCollection>();
JobCollection jobCollection = subdomain.GetCollection<JobCollection>();

If you want me to look at your model, please forward it to

Jun 27, 2010 at 11:44 PM

Thanks for your help! I obviously hadn't looked into the SelectCommands.  I've emailed to you a working solution that demonstrates this example.

Based on your feedback, this sample code will retrieve both Client and Person into the same SubDomain, and apply the updates to each within the same transaction:

Client client = Client.SelectUsingPK( 1 );  // get the client
client.ParentCollection.SubDomain.AddSelectCommand( new PersonSelectByPks( client.Partyid ) );
Person person = client.ParentCollection.SubDomain.GetCollection<PersonCollection>()[ 0 ];
client.Birthdate = DateTime.Now;
person.Fullname = person.Fullname + ", updated!";

I'm still left wondering though... Is it possible to walk from a parent object to it's child?

Data model diagram: