@@ -217,13 +217,21 @@ public Task<bool> ExistsAsync(string partitionKey, string resourceKey, Cancellat
217217 return Task . FromResult < bool > ( this . Collection . Count ( x => x . ResourceKey == resourceKey ) > 0 ) ;
218218 }
219219
220+ /// <inheritdoc />
221+ public Task < ItemEnvelope ? > GetAsync ( string id , CancellationToken cancellationToken )
222+ {
223+ var result = this . Collection . FindOne ( x => x . Id == id ) ;
224+
225+ return Task . FromResult < ItemEnvelope ? > ( result ) ;
226+ }
227+
220228 /// <inheritdoc />
221229 public Task < ItemEnvelope ? > GetAsync ( string partitionKey , string resourceKey , CancellationToken cancellationToken )
222230 {
223231 ArgumentException . ThrowIfNullOrEmpty ( partitionKey ) ;
224232 ArgumentException . ThrowIfNullOrEmpty ( resourceKey ) ;
225233
226- var result = this . Collection . FindOne ( x => x . ResourceKey == resourceKey ) ;
234+ var result = this . Collection . FindOne ( x => x . Partition == partitionKey && x . ResourceKey == resourceKey ) ;
227235
228236 return Task . FromResult < ItemEnvelope ? > ( result ) ;
229237 }
@@ -236,7 +244,7 @@ public Task<List<ItemEnvelope>> GetFamilyAsync(string partitionKey, string resou
236244
237245 var resourceKeyPrefix = $ "{ resourceKey } /";
238246
239- var items = this . Collection . Query ( ) . Where ( x => x . ResourceKey == resourceKey || x . ResourceKey . StartsWith ( resourceKeyPrefix ) ) . ToList ( ) ;
247+ var items = this . Collection . Query ( ) . Where ( x => x . Partition == partitionKey && ( x . ResourceKey == resourceKey || x . ResourceKey . StartsWith ( resourceKeyPrefix ) ) ) . ToList ( ) ;
240248
241249 return Task . FromResult < List < ItemEnvelope > > ( items ) ;
242250 }
@@ -257,7 +265,7 @@ public Task InsertAsync(ItemEnvelope itemEnvelope, CancellationToken cancellatio
257265 lock ( LockObject )
258266 {
259267 // creates
260- this . Collection . Insert ( itemEnvelope ) ;
268+ this . Collection . Insert ( itemEnvelope . Id , itemEnvelope ) ;
261269 }
262270
263271 //save out entity?
@@ -279,7 +287,8 @@ public Task UpdateAsync(ItemEnvelope itemEnvelope, CancellationToken cancellatio
279287 lock ( LockObject )
280288 {
281289 // creates (if missing) or replaces entity
282- this . Collection . Upsert ( itemEnvelope . ResourceKey , itemEnvelope ) ;
290+ bool updated = this . Collection . Update ( itemEnvelope . Id , itemEnvelope ) ;
291+ if ( ! updated ) { throw new InvalidOperationException ( $ "Unable to update ItemEnvelope with ResourceKey '{ itemEnvelope . ResourceKey } ' because it does not exist.") ; }
283292 }
284293
285294 //save out entity?
0 commit comments