1- // Copyright (C) 2009-2020 Xtensive LLC.
1+ // Copyright (C) 2009-2026 Xtensive LLC.
22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44// Created by: Dmitri Maximov
@@ -204,6 +204,21 @@ public static Entity Single(Key key)
204204 return Session . Demand ( ) . Query . Single ( key ) ;
205205 }
206206
207+ /// <summary>
208+ /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
209+ /// in the current <see cref="Session"/>.
210+ /// </summary>
211+ /// <param name="key">The key to resolve.</param>
212+ /// <param name="token">The token to cancel this operation.</param>
213+ /// <returns>
214+ /// The <see cref="Entity"/> specified <paramref name="key"/> identifies.
215+ /// </returns>
216+ /// <exception cref="KeyNotFoundException">Entity with the specified key is not found.</exception>
217+ public static ValueTask < Entity > SingleAsync ( Key key , CancellationToken token = default )
218+ {
219+ return Session . Demand ( ) . Query . SingleAsync ( key , token ) ;
220+ }
221+
207222 /// <summary>
208223 /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
209224 /// in the current <see cref="Session"/>.
@@ -213,7 +228,8 @@ public static Entity Single(Key key)
213228 /// The <see cref="Entity"/> specified <paramref name="key"/> identifies.
214229 /// <see langword="null"/>, if there is no such entity.
215230 /// </returns>
216- [ CanBeNull ] public static Entity SingleOrDefault ( Key key )
231+ [ CanBeNull ]
232+ public static Entity SingleOrDefault ( Key key )
217233 {
218234 return Session . Demand ( ) . Query . SingleOrDefault ( key ) ;
219235 }
@@ -222,18 +238,51 @@ [CanBeNull] public static Entity SingleOrDefault(Key key)
222238 /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
223239 /// in the current <see cref="Session"/>.
224240 /// </summary>
225- /// <typeparam name="T">Type of the entity.</typeparam>
226241 /// <param name="key">The key to resolve.</param>
242+ /// <param name="token">The token to cancel this operation.</param>
227243 /// <returns>
228244 /// The <see cref="Entity"/> specified <paramref name="key"/> identifies.
229245 /// <see langword="null"/>, if there is no such entity.
230246 /// </returns>
247+ [ CanBeNull ]
248+ public static ValueTask < Entity > SingleOrDefaultAsync ( Key key , CancellationToken token = default )
249+ {
250+ return Session . Demand ( ) . Query . SingleOrDefaultAsync ( key , token ) ;
251+ }
252+
253+ /// <summary>
254+ /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
255+ /// in the current <see cref="Session"/>.
256+ /// </summary>
257+ /// <typeparam name="T">Type of the entity.</typeparam>
258+ /// <param name="key">The key to resolve.</param>
259+ /// <returns>
260+ /// The <see cref="Entity"/> specified <paramref name="key"/> identifies.
261+ /// </returns>
262+ /// <exception cref="KeyNotFoundException">Entity with the specified key is not found.</exception>
231263 public static T Single < T > ( Key key )
232264 where T : class , IEntity
233265 {
234266 return Session . Demand ( ) . Query . Single < T > ( key ) ;
235267 }
236268
269+ /// <summary>
270+ /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
271+ /// in the current <see cref="Session"/>.
272+ /// </summary>
273+ /// <typeparam name="T">Type of the entity.</typeparam>
274+ /// <param name="key">The key to resolve.</param>
275+ /// <param name="token">The token to cancel this operation.</param>
276+ /// <returns>
277+ /// The <see cref="Entity"/> specified <paramref name="key"/> identifies.
278+ /// </returns>
279+ /// <exception cref="KeyNotFoundException">Entity with the specified key is not found.</exception>
280+ public static Task < T > SingleAsync < T > ( Key key , CancellationToken token = default )
281+ where T : class , IEntity
282+ {
283+ return Session . Demand ( ) . Query . SingleAsync < T > ( key , token ) ;
284+ }
285+
237286 /// <summary>
238287 /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="keyValues"/>
239288 /// in the current <see cref="Session"/>.
@@ -242,14 +291,31 @@ public static T Single<T>(Key key)
242291 /// <param name="keyValues">Key values.</param>
243292 /// <returns>
244293 /// The <see cref="Entity"/> specified <paramref name="keyValues"/> identify.
245- /// <see langword="null"/>, if there is no such entity.
246294 /// </returns>
295+ /// <exception cref="KeyNotFoundException">Entity with the specified key is not found.</exception>
247296 public static T Single < T > ( params object [ ] keyValues )
248297 where T : class , IEntity
249298 {
250299 return Session . Demand ( ) . Query . Single < T > ( keyValues ) ;
251300 }
252301
302+ /// <summary>
303+ /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="keyValues"/>
304+ /// in the current <see cref="Session"/>.
305+ /// </summary>
306+ /// <typeparam name="T">Type of the entity.</typeparam>
307+ /// <param name="keyValues">Key values.</param>
308+ /// <param name="token">The token to cancel this operation.</param>
309+ /// <returns>
310+ /// The <see cref="Entity"/> specified <paramref name="keyValues"/> identify.
311+ /// </returns>
312+ /// <exception cref="KeyNotFoundException">Entity with the specified key is not found.</exception>
313+ public static Task < T > SingleAsync < T > ( object [ ] keyValues , CancellationToken token )
314+ where T : class , IEntity
315+ {
316+ return Session . Demand ( ) . Query . SingleAsync < T > ( keyValues , token ) ;
317+ }
318+
253319 /// <summary>
254320 /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
255321 /// in the current <see cref="Session"/>.
@@ -258,13 +324,33 @@ public static T Single<T>(params object[] keyValues)
258324 /// <param name="key">The key to resolve.</param>
259325 /// <returns>
260326 /// The <see cref="Entity"/> specified <paramref name="key"/> identifies.
327+ /// <see langword="null"/>, if there is no such entity.
261328 /// </returns>
262- [ CanBeNull ] public static T SingleOrDefault < T > ( Key key )
329+ [ CanBeNull ]
330+ public static T SingleOrDefault < T > ( Key key )
263331 where T : class , IEntity
264332 {
265333 return Session . Demand ( ) . Query . SingleOrDefault < T > ( key ) ;
266334 }
267335
336+ /// <summary>
337+ /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="key"/>
338+ /// in the current <see cref="Session"/>.
339+ /// </summary>
340+ /// <typeparam name="T">Type of the entity.</typeparam>
341+ /// <param name="key">The key to resolve.</param>
342+ /// <param name="token">The token to cancel this operation.</param>
343+ /// <returns>
344+ /// The <see cref="Entity"/> specified <paramref name="key"/> identifies.
345+ /// <see langword="null"/>, if there is no such entity.
346+ /// </returns>
347+ [ CanBeNull ]
348+ public static Task < T > SingleOrDefaultAsync < T > ( Key key , CancellationToken token )
349+ where T : class , IEntity
350+ {
351+ return Session . Demand ( ) . Query . SingleOrDefaultAsync < T > ( key , token ) ;
352+ }
353+
268354 /// <summary>
269355 /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="keyValues"/>
270356 /// in the current <see cref="Session"/>.
@@ -273,13 +359,32 @@ [CanBeNull] public static T SingleOrDefault<T>(Key key)
273359 /// <param name="keyValues">Key values.</param>
274360 /// <returns>
275361 /// The <see cref="Entity"/> specified <paramref name="keyValues"/> identify.
362+ /// <see langword="null"/>, if there is no such entity.
276363 /// </returns>
277- [ CanBeNull ] public static T SingleOrDefault < T > ( params object [ ] keyValues )
364+ [ CanBeNull ]
365+ public static T SingleOrDefault < T > ( params object [ ] keyValues )
278366 where T : class , IEntity
279367 {
280368 return Session . Demand ( ) . Query . SingleOrDefault < T > ( keyValues ) ;
281369 }
282370
371+ /// <summary>
372+ /// Resolves (gets) the <see cref="Entity"/> by the specified <paramref name="keyValues"/>
373+ /// in the current <see cref="Session"/>.
374+ /// </summary>
375+ /// <typeparam name="T">Type of the entity.</typeparam>
376+ /// <param name="keyValues">Key values.</param>
377+ /// <param name="token">The token to cancel this operation.</param>
378+ /// <returns>
379+ /// The <see cref="Entity"/> specified <paramref name="keyValues"/> identify.
380+ /// <see langword="null"/>, if there is no such entity.
381+ /// </returns>
382+ public static Task < T > SingleOrDefault < T > ( object [ ] keyValues , CancellationToken token )
383+ where T : class , IEntity
384+ {
385+ return Session . Demand ( ) . Query . SingleOrDefaultAsync < T > ( keyValues , token ) ;
386+ }
387+
283388 #region Execute
284389
285390 /// <summary>
0 commit comments