ensures the generic base class static query instance is lazily created
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Umbraco.Core.Persistence.Mappers
|
||||
{
|
||||
return byAttribute.Result;
|
||||
}
|
||||
throw new Exception("Invalid Type: A Mapper could not be resolved based on the passed in Type");
|
||||
throw new Exception("Invalid Type: A Mapper could not be resolved based on the passed in Type " + type);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
#region Static Queries
|
||||
|
||||
private readonly IQuery<TEntity> _hasIdQuery = Query<TEntity>.Builder.Where(x => x.Id != 0);
|
||||
private IQuery<TEntity> _hasIdQuery;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -117,6 +117,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
RuntimeCache,
|
||||
new RepositoryCachePolicyOptions(() =>
|
||||
{
|
||||
//create it once if it is needed (no need for locking here)
|
||||
if (_hasIdQuery == null)
|
||||
{
|
||||
_hasIdQuery = Query<TEntity>.Builder.Where(x => x.Id != 0);
|
||||
}
|
||||
|
||||
//Get count of all entities of current type (TEntity) to ensure cached result is correct
|
||||
return PerformCount(_hasIdQuery);
|
||||
})));
|
||||
|
||||
Reference in New Issue
Block a user