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!
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
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