I have a problem with rewriting part of my code to generic function which would be used in other methods.
this is example of code i want to rewrite:
if(!await _bikeDbContext.Order.AnyAsync(x => x.OrderId == orderId))
{
throw new BusinessNotFoundException("Order was not found");
}
and this is something i'd like to have:
await _bikeDbContext.Order.IsAnyRule(x => x.OrderId == orderId));
I started writing code on my own but I have no clue what to put in function's body
public static void IsAnyRule<TEntity>(TEntity entity)
where TEntity : class
{
}
DbSet<T>.Findis already generic..Any(...)is already generic. Why do you want something else? What actual problem are you trying to solve?.FirstOrAsyncwill load the entity or return null if it's missing.