public IEnumerable <T> ExecuteMany <T>(QueryDescription query, ObjectBinder objectBinder) { //// Check if the container-scoped cache already has results for this exact query in which case return the same //return ContainerScopedCache.GetOrCreateTyped<IEnumerable<T>>( // CacheKey.Create(new HiveQueryCacheKey(query)), // () => // { var totalOutput = new HashSet <T>(); foreach (var reader in _repositoryPool) { reader.ExecuteMany <T>(query, objectBinder) .Cast <IReferenceByHiveId>() .SkipWhile(RepositoryGroupExtensions.SkipAndMergeFromProviders(reader.ProviderMetadata, totalOutput.Cast <IReferenceByHiveId>())) .ForEach(x => totalOutput.Add((T)x)); } var results = totalOutput.Cast <IReferenceByHiveId>().DistinctBy(x => x.Id) .Select(x => RepositoryGroupExtensions.ProcessIdsAndGroupRelationProxyDelegate(_groupRepo, _idRoot, x)) .Cast <T>(); // Raise event with the result of the query FrameworkContext.TaskManager.ExecuteInContext(TaskTriggers.Hive.PostQueryResultsAvailable, this, new TaskEventArgs(FrameworkContext, new HiveQueryResultEventArgs(results, query, ContainerScopedCache))); // Return return(results); //}); }
public T ExecuteSingle <T>(QueryDescription query, ObjectBinder objectBinder) { //return ContainerScopedCache.GetOrCreateTyped( // CacheKey.Create(new HiveQueryCacheKey(query)), // () => // { // Run query on all providers, check for result type and sum / count etc. on all results var result = _repositoryPool .Select(reader => reader.ExecuteSingle <T>(query, objectBinder)) .FirstOrDefault(); var casted = result as IReferenceByHiveId; if (casted != null) { RepositoryGroupExtensions.ProcessIdsAndGroupRelationProxyDelegate(_groupRepo, _idRoot, casted); } // Raise event with the result of the query FrameworkContext.TaskManager.ExecuteInContext(TaskTriggers.Hive.PostQueryResultsAvailable, this, new TaskEventArgs(FrameworkContext, new HiveQueryResultEventArgs(result, query, ContainerScopedCache))); // Return return(result); //}); }
public void TypedEntity_Count_WithOrElseBinary_ByAttributeValue_EqualsOperator() { // Arrange var newGuid = Guid.NewGuid(); var newGuidRedHerring = Guid.NewGuid(); var entity = CreateEntityForTest(newGuid, newGuidRedHerring, ProviderSetup); // Act using (var uow = RepositoryGroupExtensions.Create((GroupUnitFactory)GroupUnitFactory)) { var query = uow.Repositories.QueryContext.Query().Where(x => x.Attribute <string>(AttributeAlias2ForQuerying) == "not-on-red-herring" || x.Attribute <string>(AttributeAlias1ForQuerying) == "my-test-value1"); // Assert Assert.AreEqual(2, query.Count()); } }
public IEnumerable <T> ExecuteMany <T>(QueryDescription query, ObjectBinder objectBinder) { //// Check if no criteria was provided, and if we're not doing a skip / take, then throw an exception //// (APN 2012 05 18 temporarily disabled while waiting on impl & config options) //if (query.Criteria == null || query.Criteria is DefaultExpression) //{ // if (!query.ResultFilters.Any(x => x.ResultFilterType == ResultFilterType.Skip || x.ResultFilterType == ResultFilterType.Take || x.ResultFilterType == ResultFilterType.SkipTake)) // { // throw new PaginationRequiredException(); // } //} //// Check if the container-scoped cache already has results for this exact query in which case return the same //return ContainerScopedCache.GetOrCreateTyped<IEnumerable<T>>( // CacheKey.Create(new HiveQueryCacheKey(query)), // () => // { var totalOutput = new HashSet <T>(); foreach (var reader in _repositoryPool) { reader.ExecuteMany <T>(query, objectBinder) .Cast <IReferenceByHiveId>() .SkipWhile(RepositoryGroupExtensions.SkipAndMergeFromProviders(reader.ProviderMetadata, totalOutput.Cast <IReferenceByHiveId>())) .ForEach(x => totalOutput.Add((T)x)); } var results = totalOutput.Cast <IReferenceByHiveId>().DistinctBy(x => x.Id) .Select(x => RepositoryGroupExtensions.ProcessIdsAndGroupRelationProxyDelegate(_groupRepo, _idRoot, x)) .Cast <T>(); // Raise event with the result of the query FrameworkContext.TaskManager.ExecuteInContext(TaskTriggers.Hive.PostQueryResultsAvailable, this, new TaskEventArgs(FrameworkContext, new HiveQueryResultEventArgs(results, query, ContainerScopedCache))); // Return return(results); //}); }
public T ExecuteScalar <T>(QueryDescription query, ObjectBinder objectBinder) { // Run query on all providers, check for result type and sum / count etc. on all results // The below is broken, need a way of knowing the return type is int etc., summing them up and still returning as T // whilst being able to compile... Relinq is great but this one thing really riles me var result = _repositoryPool .Select(entityRepositoryReader => entityRepositoryReader.ExecuteScalar <T>(query, objectBinder)) .FirstOrDefault(); var casted = result as IReferenceByHiveId; if (casted != null) { RepositoryGroupExtensions.ProcessIdsAndGroupRelationProxyDelegate(_groupRepo, _idRoot, casted); } // Raise event with the result of the query FrameworkContext.TaskManager.ExecuteInContext(TaskTriggers.Hive.PostQueryResultsAvailable, this, new TaskEventArgs(FrameworkContext, new HiveQueryResultEventArgs(result, query, ContainerScopedCache))); // Return return(result); }