-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEfDbMappedModel.Get.cs
More file actions
46 lines (42 loc) · 2.34 KB
/
Copy pathEfDbMappedModel.Get.cs
File metadata and controls
46 lines (42 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
namespace CoreEx.EntityFrameworkCore;
public partial class EfDbMappedModel<TValue, TModel, TBiDirectionMapper>
{
/// <summary>
/// Gets the value for the specified <paramref name="key"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The value where found; otherwise, <see langword="null"/>.</returns>
public Task<TValue?> GetAsync(CompositeKey key, CancellationToken cancellationToken = default) => GetAsync(Model.Args, key, cancellationToken);
/// <summary>
/// Gets the value for the specified <paramref name="key"/>.
/// </summary>
/// <param name="args">The <see cref="EfDbArgs"/>.</param>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The value where found; otherwise, <see langword="null"/>.</returns>
public async Task<TValue?> GetAsync(EfDbArgs args, CompositeKey key, CancellationToken cancellationToken = default)
{
var m = await Model.GetAsync(args, key, cancellationToken).ConfigureAwait(false);
return Mapper.From.Map(m);
}
/// <summary>
/// Gets the value for the specified <paramref name="key"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The value.</returns>
public Task<Result<TValue>> GetWithResultAsync(CompositeKey key, CancellationToken cancellationToken = default) => GetWithResultAsync(Model.Args, key, cancellationToken);
/// <summary>
/// Gets the value for the specified <paramref name="key"/>.
/// </summary>
/// <param name="args">The <see cref="EfDbArgs"/>.</param>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The value.</returns>
public async Task<Result<TValue>> GetWithResultAsync(EfDbArgs args, CompositeKey key, CancellationToken cancellationToken = default)
{
var r = await Model.GetWithResultAsync(args, key, cancellationToken).ConfigureAwait(false);
return r.IsSuccess ? Mapper.From.Map(r.Value) : r.Bind();
}
}