Exemple #1
0
        public IEnumerable <ObjectLookupResult <DataContainer> > Execute(IRdbmsProviderCommandExecutionContext executionContext)
        {
            ArgumentUtility.CheckNotNull("executionContext", executionContext);

            var objectIds = _objectIDLoadCommand.Execute(executionContext);

            return(_storageProviderCommandFactory.CreateForSortedMultiIDLookup(objectIds.ToArray()).Execute(executionContext));
        }
        public IEnumerable <ObjectLookupResult <DataContainer> > Execute(IRdbmsProviderCommandExecutionContext executionContext)
        {
            ArgumentUtility.CheckNotNull("executionContext", executionContext);

            var dataContainers = _command.Execute(executionContext);

            var dataContainersByID = new Dictionary <ObjectID, DataContainer> ();

            foreach (var dataContainer in dataContainers.Where(dc => dc != null))
            {
                // Duplicates overwrite the previous DataContainer
                dataContainersByID[dataContainer.ID] = dataContainer;
            }

            var unassociatedDataContainerIDs = new HashSet <ObjectID> (dataContainersByID.Keys);

            foreach (var objectID in _objectIDs)
            {
                var lookupResult = CreateLookupResult(objectID, dataContainersByID);
                unassociatedDataContainerIDs.Remove(lookupResult.ObjectID);
                yield return(lookupResult);
            }

            if (unassociatedDataContainerIDs.Count > 0)
            {
                var objectIDsByValue          = _objectIDs.ToLookup(id => id.Value);
                var nonMatchingIDDescriptions = unassociatedDataContainerIDs
                                                .Select(loadedID => new { LoadedID = loadedID, ExpectedIDs = objectIDsByValue[loadedID.Value] })
                                                .Select(
                    t => string.Format(
                        "Loaded DataContainer ID: {0}, expected ObjectID(s): {1}",
                        t.LoadedID,
                        t.ExpectedIDs.Any() ? string.Join(", ", t.ExpectedIDs.Distinct()) : "none"));
                var message = string.Format(
                    "The ObjectID of one or more loaded DataContainers does not match the expected ObjectIDs:{0}{1}",
                    Environment.NewLine,
                    string.Join(Environment.NewLine, nonMatchingIDDescriptions));
                throw new PersistenceException(message);
            }
        }