ensures the generic base class static query instance is lazily created

This commit is contained in:
Shannon
2016-10-27 18:45:42 +02:00
parent 3f609fdf90
commit e2d8a28087
2 changed files with 8 additions and 2 deletions

View File

@@ -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);
});
}

View File

@@ -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);
})));