Skip to content

Commit

Permalink
chore: minor changes in DbEntityResolver.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyakunin committed Sep 14, 2023
1 parent 5299830 commit efdd8cb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Stl.Fusion.EntityFramework/DbEntityResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public record Options
public Expression<Func<TDbEntity, TKey>>? KeyExtractor { get; init; }
public Expression<Func<IQueryable<TDbEntity>, IQueryable<TDbEntity>>>? QueryTransformer { get; init; }
public Action<Dictionary<TKey, TDbEntity>> PostProcessor { get; init; } = _ => { };
public int BatchSize { get; init; } = 8;
public int BatchSize { get; init; } = 14; // Max. EF.CompileQuery parameter count = 15
public Action<BatchProcessor<TKey, TDbEntity?>>? ConfigureBatchProcessor { get; init; }
public TimeSpan? Timeout { get; init; } = TimeSpan.FromSeconds(1);
public IRetryDelayer RetryDelayer { get; init; } = new RetryDelayer() {
Expand All @@ -54,7 +54,7 @@ public record Options
// ReSharper disable once StaticMemberInGenericType
protected static MethodInfo DbContextSetMethod { get; } = typeof(DbContext)
.GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Single(m => m.Name == nameof(DbContext.Set) && m.IsGenericMethod && m.GetParameters().Length == 0)
.Single(m => Equals(m.Name, nameof(DbContext.Set)) && m.IsGenericMethod && m.GetParameters().Length == 0)
.MakeGenericMethod(typeof(TDbEntity));
protected static MethodInfo QueryableWhereMethod { get; }
= new Func<IQueryable<TDbEntity>, Expression<Func<TDbEntity, bool>>, IQueryable<TDbEntity>>(Queryable.Where).Method;
Expand Down Expand Up @@ -155,12 +155,14 @@ protected Func<TDbContext, TKey[], IAsyncEnumerable<TDbEntity>> CreateCompiledQu
lambdaParameters[0] = pDbContext;
pKeys.CopyTo(lambdaParameters, 1);
var lambda = Expression.Lambda(eBody, lambdaParameters);
#pragma warning disable EF1001
var query = new CompiledAsyncEnumerableQuery<TDbContext, TDbEntity>(lambda);
#pragma warning restore EF1001

// Locating query.Execute methods
var mExecute = query.GetType()
.GetMethods()
.SingleOrDefault(m => m.Name == nameof(query.Execute)
.SingleOrDefault(m => Equals(m.Name, nameof(query.Execute))
&& m.IsGenericMethod
&& m.GetGenericArguments().Length == batchSize)
?.MakeGenericMethod(pKeys.Select(p => p.Type).ToArray());
Expand Down

0 comments on commit efdd8cb

Please sign in to comment.