private void localizeEntryIds(BundleEntry entry) { // Did we already reassign this entry.Id within this batch? if (!uriMap.ContainsKey(entry.Id)) { Uri localUri; ResourceIdentity identity; identity = new ResourceIdentity(entry.Id); // If we shared this id space, use the relative path as id if (inSharedIdSpace(entry.Id) && (identity.Collection != null && identity.Id != null)) { localUri = identity.OperationPath; // If we're about to add an entry with a numerical id > than our current // "new record counter", make sure the next new record gets an id 1 higher // than this entries id. int newIdNum = 0; if (Int32.TryParse(identity.Id, out newIdNum)) { _store.EnsureNextSequenceNumberHigherThan(newIdNum); } } else { // Otherwise, give it a new relative, local id var newResourceId = _store.GenerateNewIdSequenceNumber(); string collectionName = getCollectionNameFromEntry(entry); localUri = ResourceIdentity.Build(collectionName, newResourceId.ToString()); } uriMap.Add(entry.Id, localUri); } // Reassign the resultString to our new local resultString entry.Id = uriMap[entry.Id]; // Now, build a new version-specific link (always, no reuse) string vid = _store.GenerateNewVersionSequenceNumber().ToString(); var id = new ResourceIdentity(entry.Id).WithVersion(vid); // If the entry did carry an version-specific resultString originally, // keep it in the map so we can update references to it. if (entry.SelfLink != null) { uriMap.Add(entry.SelfLink, id); } // Assign a new version-specific link to entry entry.SelfLink = id; }