Comments in properties for collections related to entities

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 08-Mar-2007 13:09:48   

I have seen code such as this for an entity which relates to other entities e.g. User has a reference to many CodeTechnology entities.

        /// <summary> Retrieves all related entities of type 'CodeTechnologyEntity' using a relation of type 'm:n'.</summary>
        /// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiCodeTechnologies()', because 
        /// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
        public virtual CodeReviewer.CollectionClasses.CodeTechnologyCollection CodeTechnologies
        {
            get { return GetMultiCodeTechnologies(false); }
        }

What do the remarks comments really mean i.e. "because this property is rather expensive". It is recommended to use GetMultiCodeTechnologies however what does using this method provide over this property?

Does this mean retrieving the property on a number of times doesn't cache the result the first time? If it doesn't wouldn't it be useful to add to the framework an option so the entities could cache the related collections.

Certainly I've written a lot of code such as

get
{
    if( codeTechnologies == null)
   {
            // Code to build code technologies collection for entiti
   }

   return codeTechnologies ;
}

Which is essentially the lazy load pattern. Then client code doesn't have to be concerned with writing this caching code or holding references to cached object which can be in the entitiy itself.

Although I agree this probably shouldn't be in their by default and fixed, it would be useful to make this configurable.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Mar-2007 15:08:33   

Speaking about cashing or re-fetching from the database. There should be a property called AlwaysFetch_CodeTechnologies_ which when set to false, LazyLoading will fetch the collection only once (on the first access of the property). Otherwise if set to true, it will always fetch the related collection from the database.

Posts: 254
Joined: 16-Nov-2006
# Posted on: 08-Mar-2007 15:51:50   

Thanks however is there a way to alter the framework generated code through the GUI so that all such properties default to false so by default any property access is cached unless you change the properties to false.

If this isn't accessible through the GUI could this be changed through the templates easily enough?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Mar-2007 08:48:32   

Sorry I haven't mentioned this, but the default for these properties is 'false'. So you don't need to do anything.