Generic Routine for Adding Default Values in BO

Generic Routine for Adding Default Values in BO

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


Vinodonly posted on Wednesday, November 08, 2006

Attached with this post is zip file having multiple files which provides functionality of adding default values to Business Object automatically, it works in this way :-

1. Add the Tables as specified in Attachment, In short you will store :-

BO Name :- Order

Property Name :- Customer

& Value to Be set :- Xyz Co.

Also add the related stored procedure as specified.

2. Do the changes in your business Object as specifed.

Once these changes are done and new object is created, it will set up a namevaluelist based class to default values for a particular object. Generic routines are provided which loops through all the properties in the list and sets business object properties with appropriate default values.

Advantage of using this is less code and one time only you can retreive the default value list from database and can create objects with default values without using database connection.

pls try this and advise your comments/feedback.

 

 

 

Vinodonly replied on Wednesday, November 08, 2006

i will be also posting additional code for getting lists for business object for filling comboboxes, autocomplete entries etc. later.

tiago replied on Wednesday, November 08, 2006

This is a nice idea. How about publishing it on CSLAcontrib? http://www.codeplex.com/Wiki/View.aspx?ProjectName=CSLAcontrib

Vinodonly replied on Thursday, November 09, 2006

Thanks for your comments.

Kindly note that i will complete the code to support lists, combo boxes etc. and post it here. 

I beleive for putting it on CSLAContrib, we need Permission from Rocky, so i will send this by email to him also so he can decide and advise his comments.

JoOfMetL replied on Thursday, November 09, 2006


why put the code in the constructor and not in DataPortal_Create ?

Vinodonly replied on Thursday, November 09, 2006

You are correct. i will rectify the code. Also i have changed the code to be more generic

If mDefaultValueList Is Nothing Then

mDefaultValueList = DefaultValueList.GetList(TypeName(Me))

End If

Library.Utilities.SetDefaultValues(Me, mDefaultValueList)

 

Additionally SetDefaultValues is also converted to Sub i/o Function, i will be posting final code with combobox support soon.

 

 

Vinodonly replied on Thursday, November 09, 2006

I missed one point here.

I think new constructor will be called in all cases i.e. if you have dataportal create with parameter or without parameter, so putting code in new will take care of all overloads..

pls correct me if I'm wrong...

JoOfMetL replied on Thursday, November 09, 2006


It seems to to me that in the last version of CSLA, DataPortal_Create have no parameter.

You need only to put the Default Value when it is a new object, not when the object is load from DataBase.

Vinodonly replied on Monday, November 13, 2006

Updated code is uploaded in below given post

http://forums.lhotka.net/forums/thread/9126.aspx

Copyright (c) Marimer LLC