Create object based on another.Create object based on another.
Old forum URL: forums.lhotka.net/forums/t/7058.aspx
whelzer posted on Monday, June 08, 2009
Small issue (I think)
I've got Object A - inherited from BB.
I've also got Object B also inherited from BB.
I need to create an instance of Object A based on the values from Object B. (they're are approx 90 properties in total).
Should I do pass in the entire object B to object A, eg:
public shared GetObjectA_basedOnB(byval b as ObjectB)
call a DP_fetch which basically transfers the values:
ObjectA.prop1 = ObjectB.prop1
ObjectA.prop2 = ObjectB.prop2
end sub
Or
Just pass in the ObjectB Id and let it do a fetch/find
public shared GetObjectA_basedOnB(byval bID as Integer)
Call a DP_Fetch which does this..
Dim b as objectB = objectB.GetB(bID)
then the property transfer.
End sub
Very little difference really but I'd to know whats the practice - I could use also DTO but it seems like a waste. I'm using VB/Winforms if that helps..
triplea replied on Monday, June 08, 2009
I would use your first approach but call DP_Create running locally.
I wouldn't use the second approach, it looks less readable since you perform a fetch on object A while really you are performing that action on object B and then copying the values.
JoeFallon1 replied on Monday, June 08, 2009
You should try out the DataMapper class to copy the values from one BO to another. It is quite flexible and it also has an excluded properties list.
Joe
whelzer replied on Monday, June 08, 2009
Spot on. Thanks. DP_Create makes much more sense.
Edit: Joe I'm using v 3.0.4 is the DataMapper avilable to me. Ta
whelzer replied on Monday, June 08, 2009
Just checked out the DataMapper p285 2005 VB Book. Superb piece of functionality!
Don't know why I never came across it before. Glad I didn't write all 90 lines out...
Copyright (c) Marimer LLC