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.