@@ -29,7 +29,8 @@ public static void Add<TEntity>(this IWorkContext context, TEntity entity)
29
29
/// <param name="context">The work context to get the repository.</param>
30
30
/// <param name="entity">The new entity instance.</param>
31
31
/// <param name="token">Cancellation token.</param>
32
- public static ValueTask AddAsync < TEntity > ( this IWorkContext context , TEntity entity , CancellationToken token = default )
32
+ public static ValueTask AddAsync < TEntity > ( this IWorkContext context , TEntity entity ,
33
+ CancellationToken token = default )
33
34
where TEntity : class
34
35
=> context . Repository < TEntity > ( ) . AddAsync ( entity , token ) ;
35
36
@@ -43,7 +44,7 @@ public static ValueTask AddAsync<TEntity>(this IWorkContext context, TEntity ent
43
44
public static void AddRange < TEntity > ( this IWorkContext context , IEnumerable < TEntity > entities )
44
45
where TEntity : class
45
46
=> context . Repository < TEntity > ( ) . AddRange ( entities ) ;
46
-
47
+
47
48
/// <summary>
48
49
/// <para>
49
50
/// Finds an existing entity through its unique identity (id).
@@ -73,7 +74,8 @@ public static void AddRange<TEntity>(this IWorkContext context, IEnumerable<TEnt
73
74
/// Existing instance, or null/default if it does not exist.
74
75
/// </para>
75
76
/// </returns>
76
- public static ValueTask < TEntity ? > FindAsync < TEntity > ( this IWorkContext context , object id , CancellationToken token = default )
77
+ public static ValueTask < TEntity ? > FindAsync < TEntity > ( this IWorkContext context , object id ,
78
+ CancellationToken token = default )
77
79
where TEntity : class
78
80
=> context . Repository < TEntity > ( ) . FindAsync ( id , token ) ;
79
81
@@ -92,10 +94,78 @@ public static void AddRange<TEntity>(this IWorkContext context, IEnumerable<TEnt
92
94
/// An entry representing the entity record obtained from the database.
93
95
/// </para>
94
96
/// </returns>
95
- public static ValueTask < Entry < TEntity , TId > > FindAsync < TEntity , TId > ( this IWorkContext context , Id < TEntity , TId > id , CancellationToken token = default )
97
+ public static ValueTask < Entry < TEntity , TId > > FindAsync < TEntity , TId > ( this IWorkContext context , Id < TEntity , TId > id ,
98
+ CancellationToken token = default )
96
99
where TEntity : class
97
100
=> context . Repository < TEntity > ( ) . FindAsync ( id , token ) ;
98
101
102
+ /// <summary>
103
+ /// <para>
104
+ /// Finds an existing entity through its Guid.
105
+ /// </para>
106
+ /// </summary>
107
+ /// <param name="context">The work context to get the repository.</param>
108
+ /// <param name="guid">The entity Guid.</param>
109
+ /// <returns>
110
+ /// <para>
111
+ /// Existing instance, or null/default if it does not exist.
112
+ /// </para>
113
+ /// </returns>
114
+ public static TEntity ? FindByGuid < TEntity > ( this IWorkContext context , Guid guid )
115
+ where TEntity : class , IHasGuid
116
+ => context . GetService < IFinderByGuid < TEntity > > ( ) . FindByGuid ( guid ) ;
117
+
118
+ /// <summary>
119
+ /// <para>
120
+ /// Finds an existing entity through its Guid.
121
+ /// </para>
122
+ /// </summary>
123
+ /// <param name="context">The work context to get the repository.</param>
124
+ /// <param name="guid">The entity Guid.</param>
125
+ /// <param name="token">Token for cancelling tasks.</param>
126
+ /// <returns>
127
+ /// <para>
128
+ /// Existing instance, or null/default if it does not exist.
129
+ /// </para>
130
+ /// </returns>
131
+ public static Task < TEntity ? > FindByGuidAsync < TEntity > ( this IWorkContext context , Guid guid ,
132
+ CancellationToken token = default )
133
+ where TEntity : class , IHasGuid
134
+ => context . GetService < IFinderByGuid < TEntity > > ( ) . FindByGuidAsync ( guid , token ) ;
135
+
136
+ /// <summary>
137
+ /// <para>
138
+ /// Finds an existing entity through its Code.
139
+ /// </para>
140
+ /// </summary>
141
+ /// <param name="context">The work context to get the repository.</param>
142
+ /// <param name="code">The entity code.</param>
143
+ /// <returns>
144
+ /// <para>
145
+ /// Existing instance, or null/default if it does not exist.
146
+ /// </para>
147
+ /// </returns>
148
+ public static TEntity ? FindByCode < TEntity , TCode > ( this IWorkContext context , TCode code )
149
+ where TEntity : class , IHasCode < TCode >
150
+ => context . GetService < IFinderByCode < TEntity , TCode > > ( ) . FindByCode ( code ) ;
151
+
152
+ /// <summary>
153
+ /// <para>
154
+ /// Finds an existing entity through its Code.
155
+ /// </para>
156
+ /// </summary>
157
+ /// <param name="context">The work context to get the repository.</param>
158
+ /// <param name="code">The entity code.</param>
159
+ /// <param name="token">Token for cancelling tasks.</param>
160
+ /// <returns>
161
+ /// <para>
162
+ /// Existing instance, or null/default if it does not exist.
163
+ /// </para>
164
+ /// </returns>
165
+ public static Task < TEntity ? > FindByCodeAsync < TEntity , TCode > ( this IWorkContext context , TCode code , CancellationToken token = default )
166
+ where TEntity : class , IHasCode < TCode >
167
+ => context . GetService < IFinderByCode < TEntity , TCode > > ( ) . FindByCodeAsync ( code , token ) ;
168
+
99
169
/// <summary>
100
170
/// <para>
101
171
/// Operation to merge a data model to an existing entity.
@@ -143,7 +213,8 @@ public static IEnumerable<bool> MergeRange<TEntity, TId>(this IWorkContext conte
143
213
/// True if the entity exists and has been updated, false otherwise.
144
214
/// </para>
145
215
/// </returns>
146
- public static Task < bool > MergeAsync < TEntity , TId > ( this IWorkContext context , IHasId < TId > model , CancellationToken token = default )
216
+ public static Task < bool > MergeAsync < TEntity , TId > ( this IWorkContext context , IHasId < TId > model ,
217
+ CancellationToken token = default )
147
218
where TEntity : class
148
219
=> context . Repository < TEntity > ( ) . MergeAsync ( model , token ) ;
149
220
@@ -164,7 +235,7 @@ public static Task<bool> MergeAsync<TEntity, TId>(this IWorkContext context, IHa
164
235
/// True if the entity exists and has been updated, false otherwise.
165
236
/// </para>
166
237
/// </returns>
167
- public static Task < bool > MergeAsync < TEntity , TId , TModel > ( this IWorkContext context ,
238
+ public static Task < bool > MergeAsync < TEntity , TId , TModel > ( this IWorkContext context ,
168
239
Id < TEntity , TId > id , TModel model , CancellationToken token = default )
169
240
where TEntity : class
170
241
where TModel : class
@@ -193,7 +264,7 @@ public static Task<IEnumerable<bool>> MergeRangeAsync<TEntity, TId>(
193
264
/// </summary>
194
265
/// <param name="context">The work context to get the repository.</param>
195
266
/// <param name="entity">The entity.</param>
196
- public static void Remove < TEntity > ( this IWorkContext context , TEntity entity )
267
+ public static void Remove < TEntity > ( this IWorkContext context , TEntity entity )
197
268
where TEntity : class
198
269
=> context . Repository < TEntity > ( ) . Remove ( entity ) ;
199
270
@@ -256,7 +327,8 @@ public static void RemoveRange<TEntity>(this IWorkContext context, IEnumerable<T
256
327
/// The entity excluded, or null if the entity is not found.
257
328
/// </para>
258
329
/// </returns>
259
- public static Task < TEntity ? > DeleteAsync < TEntity > ( this IWorkContext context , object id , CancellationToken token = default )
330
+ public static Task < TEntity ? > DeleteAsync < TEntity > ( this IWorkContext context , object id ,
331
+ CancellationToken token = default )
260
332
where TEntity : class
261
333
=> context . Repository < TEntity > ( ) . DeleteAsync ( id , token ) ;
262
334
0 commit comments