From dc5ae0f1ac197792c13f6ab9a706f8d034e034d3 Mon Sep 17 00:00:00 2001 From: JJ Bussert Date: Tue, 23 Nov 2021 17:21:04 -0600 Subject: [PATCH] Removed Async Repository methods because EFCore does not support multiple thread access to a single context which was the original intent of the functionality --- src/E13.Common.Data.Db/IRepository.cs | 49 -------------- src/E13.Common.Data.Db/Repository.cs | 98 --------------------------- 2 files changed, 147 deletions(-) diff --git a/src/E13.Common.Data.Db/IRepository.cs b/src/E13.Common.Data.Db/IRepository.cs index 7c7a904..504fd85 100644 --- a/src/E13.Common.Data.Db/IRepository.cs +++ b/src/E13.Common.Data.Db/IRepository.cs @@ -63,32 +63,6 @@ TResult GetFirstOrDefault(Expression> selector, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null); - /// - /// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method defaults to a read-only, no-tracking query. - /// - /// The selector for projection. - /// A function to test each element for a condition. - /// A function to order elements. - /// A function to include navigation properties - /// An that contains elements that satisfy the condition specified by . - /// Ex: This method defaults to a read-only, no-tracking query. - Task GetFirstOrDefaultAsync(Expression> selector, - Expression> predicate = null, - Func, IOrderedQueryable> orderBy = null, - Func, IIncludableQueryable> include = null); - - /// - /// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method defaults to a read-only, no-tracking query. - /// - /// A function to test each element for a condition. - /// A function to order elements. - /// A function to include navigation properties - /// An that contains elements that satisfy the condition specified by . - /// Ex: This method defaults to a read-only, no-tracking query. - Task GetFirstOrDefaultAsync(Expression> predicate = null, - Func, IOrderedQueryable> orderBy = null, - Func, IIncludableQueryable> include = null); - /// /// Gets the count based on a predicate. /// @@ -114,29 +88,6 @@ Task GetFirstOrDefaultAsync(Expression> predicate = /// The entities to insert. void Insert(IEnumerable entities); - /// - /// Inserts a new entity asynchronously. - /// - /// The entity to insert. - /// A to observe while waiting for the task to complete. - /// A that represents the asynchronous insert operation. - ValueTask> InsertAsync(TEntity entity, CancellationToken cancellationToken = default); - - /// - /// Inserts a range of entities asynchronously. - /// - /// The entities to insert. - /// A that represents the asynchronous insert operation. - Task InsertAsync(params TEntity[] entities); - - /// - /// Inserts a range of entities asynchronously. - /// - /// The entities to insert. - /// A to observe while waiting for the task to complete. - /// A that represents the asynchronous insert operation. - Task InsertAsync(IEnumerable entities, CancellationToken cancellationToken = default); - /// /// Updates the specified entity. /// diff --git a/src/E13.Common.Data.Db/Repository.cs b/src/E13.Common.Data.Db/Repository.cs index 2457149..5bd5000 100644 --- a/src/E13.Common.Data.Db/Repository.cs +++ b/src/E13.Common.Data.Db/Repository.cs @@ -166,34 +166,6 @@ public virtual TEntity GetFirstOrDefault(Expression> predica } } - - /// - public virtual async Task GetFirstOrDefaultAsync(Expression> predicate = null, - Func, IOrderedQueryable> orderBy = null, - Func, IIncludableQueryable> include = null) - { - IQueryable query = DbSet; - - if (include != null) - { - query = include(query); - } - - if (predicate != null) - { - query = query.Where(predicate); - } - - if (orderBy != null) - { - return await orderBy(query).FirstOrDefaultAsync().ConfigureAwait(true); - } - else - { - return await query.FirstOrDefaultAsync().ConfigureAwait(true); - } - } - /// /// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method default no-tracking query. /// @@ -230,34 +202,6 @@ public virtual TResult GetFirstOrDefault(Expression - public virtual async Task GetFirstOrDefaultAsync(Expression> selector, - Expression> predicate = null, - Func, IOrderedQueryable> orderBy = null, - Func, IIncludableQueryable> include = null) - { - IQueryable query = DbSet; - - if (include != null) - { - query = include(query); - } - - if (predicate != null) - { - query = query.Where(predicate); - } - - if (orderBy != null) - { - return await orderBy(query).Select(selector).FirstOrDefaultAsync().ConfigureAwait(true); - } - else - { - return await query.Select(selector).FirstOrDefaultAsync().ConfigureAwait(true); - } - } - /// /// Gets the count based on a predicate. /// @@ -296,38 +240,6 @@ public virtual void Insert(TEntity entity) /// The entities to insert. public virtual void Insert(IEnumerable entities) => DbSet.AddRange(entities); - /// - /// Inserts a new entity asynchronously. - /// - /// The entity to insert. - /// A to observe while waiting for the task to complete. - /// A that represents the asynchronous insert operation. - public virtual ValueTask> InsertAsync(TEntity entity, CancellationToken cancellationToken = default) - { - return DbSet.AddAsync(entity, cancellationToken); - - // Shadow properties? - //var property = _dbContext.Entry(entity).Property("Created"); - //if (property != null) { - //property.CurrentValue = DateTime.Now; - //} - } - - /// - /// Inserts a range of entities asynchronously. - /// - /// The entities to insert. - /// A that represents the asynchronous insert operation. - public virtual Task InsertAsync(params TEntity[] entities) => DbSet.AddRangeAsync(entities); - - /// - /// Inserts a range of entities asynchronously. - /// - /// The entities to insert. - /// A to observe while waiting for the task to complete. - /// A that represents the asynchronous insert operation. - public virtual Task InsertAsync(IEnumerable entities, CancellationToken cancellationToken = default) => DbSet.AddRangeAsync(entities, cancellationToken); - /// /// Updates the specified entity. /// @@ -337,16 +249,6 @@ public virtual void Update(TEntity entity) DbSet.Update(entity); } - /// - /// Updates the specified entity. - /// - /// The entity. - public virtual void UpdateAsync(TEntity entity) - { - DbSet.Update(entity); - - } - /// /// Updates the specified entities. ///