using Raven.Client.Documents.Linq; namespace zero.Stores; public static class EntityStoreExtensions { /// /// Stream the collection /// public static IAsyncEnumerable Stream(this IEntityStore store) where T : ZeroIdEntity, ISupportsFlavors, ISupportsSorting, new() => store.Stream(null); /// /// Deletes an entity by Id /// public static async Task> Delete(this IEntityStore store, string id) where T : ZeroIdEntity, ISupportsFlavors, ISupportsSorting, new() => await store.Delete(await store.Load(id)); /// /// Deletes entities by Id /// public static async Task Delete(this IEntityStore store, IEnumerable ids) where T : ZeroIdEntity, ISupportsFlavors, ISupportsSorting, new() => await store.Delete((await store.Load(ids)).Select(x => x.Value)); /// /// Deletes entities /// public static async Task Delete(this IEntityStore store, IEnumerable models) where T : ZeroIdEntity, ISupportsFlavors, ISupportsSorting, new() { int successCount = 0; foreach (T model in models) { Result result = await store.Delete(model); successCount += result.IsSuccess ? 1 : 0; } return successCount; } /// /// Deletes an entity by Id with all descendents /// public static async Task> DeleteWithDescendants(this ITreeEntityStore store, string id) where T : ZeroIdEntity, ISupportsTrees, ISupportsFlavors, ISupportsSorting, new() => await store.DeleteWithDescendants(await store.Load(id)); }