Thursday, January 17, 2008
Generic Sub Item Collections in Business Entities
The latest Milos version has a pretty neat enhancement in the business entity model: Sub item collections are now available as generics. Here's why that's cool:
So far, in order to create collections of sub items in business entities ("1-to-many relationships"), one had to create the individual item objects, as well as a collection class that could hold those items. The trouble with that is that it is a lot of work to create the collection class, and the only benefit of this class is a strongly typed interface. (The strongly typed interface is needed so one can access parent.Children[x] and then get all the properties on that object).
Using the new generic version of the sub item collection, one usually does not have to create a subclass. Instead, one just creates the class for the individual items, and then instantiates the generic version of the collection, with the generic being the item type.
Example: An invoice entity with a line item collection could simply instantiate an appropriate collection like so:
protected override void LoadSubItemCollections()
For more details and a detailed explanation, consult the "How-To: Creating a Collection of Child Items" topic in the Milos documentation.
Of course, the old way is still supported as well. The main benefit of using the generic version is in creating collections by hand. When using any of the code generator tools, one isn't exposed to the collection anyway (in most cases), so the benefit is minimal. So far, the code generator tools do not use the generic collection yet. There are considerations around backward compatibility. However, we are considering to change the tools in the future...
Posted @ 4:05 PM by Egger, Markus (firstname.lastname@example.org) -
Post a Comment:
Comment Title (required):
Your Name (optional):
Your Email (optional):
Your Web Site (optional):
Your Comment (required):