Creating Dependant Objects Best Practice

Creating Dependant Objects Best Practice

Old forum URL: forums.lhotka.net/forums/t/7158.aspx


Adam posted on Wednesday, June 24, 2009

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

Hi there

I have a database that has been optimized for storage and I am having great difficulty adding Business Logic to create dependant objects. For example of Business Objects please see attached class diagram.

 

I have the following business rules;

1.       A client has one or more Client Histories. A Client History row is to be created when I create a Client.

2.       Client History must have an associated Client Core Details row.

3.       Client Core Details are optimized such that a Client Core Detail row can be associated with many Client Histories as Client Core Details data changes rarely.

So on creating a new client I need to create a new (with defaults) Client History row and Client Core Details row and glue them together.

Currently I have tried the following code;

partial void OnCreated()

{

   var CCD = ClientCoreDetail.NewClientCoreDetail();

   var CCH = ClientHistory.NewClientHistory();

   CCH.ClientId = this.Id;

   CCD.ClientHistories.Add(CCH);

   this.ClientHistories.Add(CCH);       

}

Which is called from ;

protected override void DataPortal_Create()

{

   bool cancel = false;

   OnCreating(ref cancel);

   if (cancel) return;

 

   //Create Child Properties

   LoadProperty(ClientHistoriesProperty, ClientHistoryList.NewClientHistoryList());

   LoadProperty(EquipmentsProperty, EquipmentList.NewEquipmentList());

   LoadProperty(InvoicesProperty, InvoiceList.NewInvoiceList());

   ValidationRules.CheckRules();

   OnCreated();

}

This code doesn’t work and presumably is not best practice.

I believe possible options are;

a)      Change the database structure so that Client Core Details is consumed within Client History which would waste valuable storage space, which we would rather not do!

b)      Somehow instantiate dependant objects.

c)       Somehow make parent/root behave like a child.

Please help!

triplea replied on Wednesday, June 24, 2009

You are probably struggling because your use case focuses on the requirements of your database rather than the business logic behind it. The way I see it, a possible object structure would be:

Client (Root - contains fields from your Client table)
|
|----> ClientHistories (BusinessListBase<ClientHistories, ClientHistory> list of history records)
               |
               |---->ClientHistory (Editable Child - contains fields from your Code table plus - if needed - the history table)

The mapping would occur in your dataportals.

HTH

Adam replied on Monday, June 29, 2009

thanks triplea I will give that a go :)

Adam replied on Wednesday, July 01, 2009

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

Hi triplea

I have had a look at what you have suggested only to realise that what you have suggested is what I have already done using CodeSmith. The part that I am struggling with is the link between ClientHistory and ClientCoreDetails.

Any help appreciated.



Copyright (c) Marimer LLC