Code Generation and Collections

Posts   
 
    
Posts: 37
Joined: 21-Oct-2004
# Posted on: 09-Dec-2004 20:14:52   

Is there a way to restrict the designer from overwriting the collection classes when it generates code? We're using the two class scenario, and we've got some business logic in our collections (under "custom code"), and it's being overwritten every time we generate.

Still loving the mapper! Can't say how much time we've saved, but it's been a tremendous boon to our business.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 09-Dec-2004 21:55:09   

The Custom Code regions are badly named, and will be renamed soon. These regions are for the place where the include templates code is placed. For the entity collections in the 2-class scenario, it will include a template bound to the template id Custom_EntityCollectionUsingEntityBaseTemplate

So if you create a custom template set config (for example using the TemplateStudio application) and you add a template binding to the Custom_EntityCollectionUsingEntityBaseTemplate id and the file you bind to that id, you add the code to add to the entity collections.

if you want to make sure code is only added to several or just 1 collection, wrap your code in <[If StringValueEquals StringValueName "EntityName"]> // your code <[EndIF]> statements. See the SDK documentation for details. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 37
Joined: 21-Oct-2004
# Posted on: 09-Dec-2004 22:31:54   

Okay, make sense. As a suggestion for a future version, this is what we've added for our custom collections:


public void Add(<CollectionType> Items) 
        {
            foreach (IEntity Item in Items) 
            {
                this.Add(Item);
            }
        }

We wanted the ability to add one collection's values to another collection without repeating the code.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 09-Dec-2004 22:56:48   

An AddRange() kind of method? I'll add it to the todo list! simple_smile Thanks for the suggestion.

Frans Bouma | Lead developer LLBLGen Pro