Skip to content

Commit

Permalink
Removed Async Repository methods because EFCore does not support mult…
Browse files Browse the repository at this point in the history
…iple thread access to a single context which was the original intent of the functionality
  • Loading branch information
JJBussert committed Nov 23, 2021
1 parent 02e4b6b commit dc5ae0f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 147 deletions.
49 changes: 0 additions & 49 deletions src/E13.Common.Data.Db/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,6 @@ TResult GetFirstOrDefault<TResult>(Expression<Func<TEntity, TResult>> selector,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null);

/// <summary>
/// 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.
/// </summary>
/// <param name="selector">The selector for projection.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="include">A function to include navigation properties</param>
/// <returns>An <see cref="IPagedCollection{TEntity}"/> that contains elements that satisfy the condition specified by <paramref name="predicate"/>.</returns>
/// <remarks>Ex: This method defaults to a read-only, no-tracking query.</remarks>
Task<TResult> GetFirstOrDefaultAsync<TResult>(Expression<Func<TEntity, TResult>> selector,
Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null);

/// <summary>
/// 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.
/// </summary>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="include">A function to include navigation properties</param>
/// <returns>An <see cref="IPagedCollection{TEntity}"/> that contains elements that satisfy the condition specified by <paramref name="predicate"/>.</returns>
/// <remarks>Ex: This method defaults to a read-only, no-tracking query. </remarks>
Task<TEntity> GetFirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null);

/// <summary>
/// Gets the count based on a predicate.
/// </summary>
Expand All @@ -114,29 +88,6 @@ Task<TEntity> GetFirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate =
/// <param name="entities">The entities to insert.</param>
void Insert(IEnumerable<TEntity> entities);

/// <summary>
/// Inserts a new entity asynchronously.
/// </summary>
/// <param name="entity">The entity to insert.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
ValueTask<EntityEntry<TEntity>> InsertAsync(TEntity entity, CancellationToken cancellationToken = default);

/// <summary>
/// Inserts a range of entities asynchronously.
/// </summary>
/// <param name="entities">The entities to insert.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
Task InsertAsync(params TEntity[] entities);

/// <summary>
/// Inserts a range of entities asynchronously.
/// </summary>
/// <param name="entities">The entities to insert.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
Task InsertAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);

/// <summary>
/// Updates the specified entity.
/// </summary>
Expand Down
98 changes: 0 additions & 98 deletions src/E13.Common.Data.Db/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,34 +166,6 @@ public virtual TEntity GetFirstOrDefault(Expression<Func<TEntity, bool>> predica
}
}


/// <inheritdoc />
public virtual async Task<TEntity> GetFirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null)
{
IQueryable<TEntity> 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);
}
}

/// <summary>
/// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method default no-tracking query.
/// </summary>
Expand Down Expand Up @@ -230,34 +202,6 @@ public virtual TResult GetFirstOrDefault<TResult>(Expression<Func<TEntity, TResu
}
}

/// <inheritdoc />
public virtual async Task<TResult> GetFirstOrDefaultAsync<TResult>(Expression<Func<TEntity, TResult>> selector,
Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null)
{
IQueryable<TEntity> 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);
}
}

/// <summary>
/// Gets the count based on a predicate.
/// </summary>
Expand Down Expand Up @@ -296,38 +240,6 @@ public virtual void Insert(TEntity entity)
/// <param name="entities">The entities to insert.</param>
public virtual void Insert(IEnumerable<TEntity> entities) => DbSet.AddRange(entities);

/// <summary>
/// Inserts a new entity asynchronously.
/// </summary>
/// <param name="entity">The entity to insert.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
public virtual ValueTask<EntityEntry<TEntity>> 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;
//}
}

/// <summary>
/// Inserts a range of entities asynchronously.
/// </summary>
/// <param name="entities">The entities to insert.</param>
/// <returns>A <see cref="Task" /> that represents the asynchronous insert operation.</returns>
public virtual Task InsertAsync(params TEntity[] entities) => DbSet.AddRangeAsync(entities);

/// <summary>
/// Inserts a range of entities asynchronously.
/// </summary>
/// <param name="entities">The entities to insert.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
public virtual Task InsertAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default) => DbSet.AddRangeAsync(entities, cancellationToken);

/// <summary>
/// Updates the specified entity.
/// </summary>
Expand All @@ -337,16 +249,6 @@ public virtual void Update(TEntity entity)
DbSet.Update(entity);
}

/// <summary>
/// Updates the specified entity.
/// </summary>
/// <param name="entity">The entity.</param>
public virtual void UpdateAsync(TEntity entity)
{
DbSet.Update(entity);

}

/// <summary>
/// Updates the specified entities.
/// </summary>
Expand Down

0 comments on commit dc5ae0f

Please sign in to comment.