I to implement a Collection?I to implement a Collection?
Old forum URL: forums.lhotka.net/forums/t/3462.aspx
elnoegarcia posted on Friday, August 31, 2007
Hi!!
Well, in spite of the fact that I've read a couple of books over of the topic of CSLA, I've never really made any application with it until now (well, I try!!).
But I'm undecided about a property that I'm trying to implement with a collection; this property is really a list of phone numbers (think about they're of a customer of any store). The class name is Phone, which only has two properties PhoneType (home, work, movile, etc.) and Number, and I decided to save that property (that phone numbers) in only one field of a Table in my Database; I thought to concatenate all the phone numbers with separators (a Comma or a Tab for example), but what really has me woorried is ¿how to declare that property? ¿as a CSLA EditableChildList(Of Phone) or just a List(Of Phone)? ¿How can I validate that property? thinking in that the record which has the numbers comes in the same record and from the same table as well as all other properties of a single "Customer" (not as is in the project tracker sample project).
If anyone has any idea that can help me....I will appreciate it a lot!!
Best regards to everybody!
Noé
Marjon1 replied on Friday, August 31, 2007
Noé,
The way that the information is saved or retrieved from the database, is really idependent of the type of collection that you would use. As the Phone object itself, will be responsible for creating itself from the data passed to it, and that
shouldn't change between the List(Of Phone) or EditableChildList(Of Phone). If you are saving it in the same table as the customer object or not is really not the collection's problem.
The primary benefits that I can see (and anyone please feel free to correct me) to using a EditableChildList over List:
- You don't have to implement your own IsDirty or IsValid rules on the list, so that your customer object knows when you have made changes. This handles validation of the entire list, based on the validation rules of each instance within that class.
- The EditableChildList supports concepts such as Begin & ApplyEdit, and is designed with databinding in mind (if you plan to use this) and n-level undo if you plan to use. You would have to use BindingList(Of Phone) to get similar features.
- The amount of coding work (i.e fetch, insert, update, delete) is the bascially the same, but if you are using the CSLA for the rest of the objects, it would make sense to keep things consistent throughout the application; unless there is very valid reason to not use a ChildList. I've got similar objects in our application for addresses, phone numbers, and email addresses all using ChildLists without issue.
That is just my AUD$0.02
Copyright (c) Marimer LLC