mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Working on the UserRepository functionality
+ Tests + QueryableExtensions. It is an add-on that allows you to implement exceptions if the returned List would be empty.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Govor.Core.Infrastructure.Extensions;
|
||||
|
||||
public static class QueryableExtensions
|
||||
{
|
||||
public static async Task<List<T>> ToListOrThrowIfEmpty<T>(this IQueryable<T> query, Exception ex)
|
||||
{
|
||||
var list = await query.ToListAsync();
|
||||
if (list.Count == 0) throw ex;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user