Multiple instances of a business object

Multiple instances of a business object

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


gregwilliams posted on Friday, August 18, 2006

Need a little Architectural help with an implementation of a business object.

User is presented with a read only list of car options from source A
(display in grid with columns type, column2, column3, column4)

User select a record from list and is presented with:
   1. read only list of business object from datasource A 
   2. read only list of business object from datasource B
   3. editable list of business object populated from either datasource A or B

example. All three business object have the same property 'Color'. Datasource A color is Red. Datasource B is Blue. Rules engine returns Blue so 3rd business objects color property would be set to Blue.

Overall this is taking the same object scheme and populating 3 objects from 3 different datasources.

I am just starting out with CSLA and not sure if i need to do this within the Criteria section. If so can someone help with a code sample???

I don't think duplicating the class 3 times just to reference a different datasource is the correct way. right?

gregwilliams replied on Saturday, August 19, 2006

sorry, just caught a mistake. the 3 business objects are as follows.

1. read only business object from datasource A ( single record )
2. read only business obejct from datasource B ( single record )
3. editable business object populated from either datasource A or B ( single record)

dean replied on Saturday, August 19, 2006

Greg  -Maybe I am being dense, but I think we need a little more context to help. Most of these decisions come down to examining your use case(s). You are jumping right into interface issues and this tends to confuse things. So can you back up and more fully describe the use case?

Dean

gregwilliams replied on Saturday, August 19, 2006

Sorry, let me see if i can clearify.

User is presented with a grid showing trip information ( trip_number, Service, Time, ) pulled from Database A
User selects a specific trip and is redirected to a reconciliation page.
On page load display 3 columns for compairing Trip_number, Service, and time from data stored in Database A (column A) and Database B (column B). Allow users to choose a value from either Source A or Source B and populate Source C (column C)
Upon completion of the reconciliation update Source C database

My thought was to create a business object ‘Trip’ that has 3 properties (trip_number,service and time)from 3 different data sources.
 

                   [readonly]          [editable]          [readonly]
                     (Trip A)           (Trip C)              (Trip B)
Trip #             0956                                           0956
Service             new                                           old  
Time                12:00                                        13:00


After Reconciliation

                     (Trip A)        (Trip C)           (Trip B)
Trip #             0956              0956              0956
Service             new              old                 old  
Time                12:00           12:00              13:00

User select enter and Trip C is saved to the database.

I am new to using CSLA and open to any ideas.

dean replied on Saturday, August 19, 2006

For a start it sounds like you have a readonly object, TripData, that is used to populate the first screen. You would have two of these for the first screen (at least in this example - is it always limited to two?)  Then you have a ResultingTrip (you called it Trip), that is the editable object that is stored after reconciliation.

You could have ResultingTrip required references to the TripA and TripB object. This is where you would get the lookup info for you fields.

public class Trip
    inherits readonlybase
   Trip# as string?/int?
  Service as int
  Time as datetime?/int?/string?
end class

public class ResultingTrip
private  Trip# as string/int
private  Service as int
private  Time as datetime? string? int?

private TripA as trip
private TripB as trip

public TripNumberOptions as TripOptionNameValueList
public ServiceOptions as ServiceOptionNameValueList
pulbic TimeOptions as TimeOptionsNameValuelist

public shared function GetResultingTrip(TripA, TripB) as ResultingTrip
   ' populate TripNumberOptions, ServiceOptions, and TimeOptions
   ' return new ResultingTrip
end class

This would then force TripC (resultingtrip) into having values only pulled from TripA or TripB.

Does this help?

gregwilliams replied on Saturday, August 19, 2006

I see what you are doing. However, I am unclear as how to create a Trip object from two different datasources.

In referencing the PTracker code, i see the Fetch method is where one would get a Datareader and loop over that to populate the properties of the object. i need to be able to create this from two or more datasources. this is where i am getting confused. how would i create multiple "Trip" object from different datasources?

I guess i could just create two sets of properties and have two database calls, each of which would populate the appropriate properties. However i think that would be a little slopy. :-(

dean replied on Sunday, August 20, 2006

In the fetch for you single object, make two diffferent calls in the same fetch, then populate your object from each datareader. You would need two different connection strings (databaseA.connection, databaseBconnection), two different datareader/command objects.

Dean

cultofluna replied on Sunday, August 20, 2006

You can also create a TripBase object with basic functionality needed for Trip, and create two derived Trip objects where only the Fetch method differs.

gregwilliams replied on Wednesday, August 23, 2006

Thanks to all for the Ideas on the best way to handle this. I have handled this by creating a new Criteria method that will take two paramaters ( tripID, source) then in the Fetch method i conect to the proper datasource based on the source property.

I am just getting started using CSLA and Thanks for all the quick responses.

Copyright (c) Marimer LLC