using Elsa.Common.Entities;
using Microsoft.EntityFrameworkCore;
namespace Elsa.Persistence.EFCore;
///
/// A generic repository class around EF Core for accessing entities that inherit from .
///
/// The type of the database context.
/// The type of the entity.
public class EntityStore(IDbContextFactory dbContextFactory, IServiceProvider serviceProvider)
: Store(dbContextFactory, serviceProvider) where TDbContext : DbContext where TEntity : Entity, new()
{
///
/// Saves the entity.
///
/// The entity to save.
/// The cancellation token.
public async Task SaveAsync(TEntity entity, CancellationToken cancellationToken = default) => await SaveAsync(entity, null, cancellationToken);
///
/// Saves the entity.
///
/// The entity to save.
/// The callback to invoke before saving the entity.
/// The cancellation token.
public async Task SaveAsync(TEntity entity, Func? onSaving, CancellationToken cancellationToken = default) => await SaveAsync(entity, x => x.Id, onSaving, cancellationToken);
///
/// Saves the specified entities.
///
/// The entities to save.
/// The cancellation token.
public async Task SaveManyAsync(IEnumerable entities, CancellationToken cancellationToken = default) => await SaveManyAsync(entities, null, cancellationToken);
///
/// Saves the specified entities.
///
/// The entities to save.
/// The callback to invoke before saving the entities.
/// The cancellation token.
public async Task SaveManyAsync(IEnumerable entities, Func? onSaving = null, CancellationToken cancellationToken = default) => await SaveManyAsync(entities, x => x.Id, onSaving, cancellationToken);
}