Skip to content

Commit 3722aca

Browse files
committed
Add hint about EF Core issue on async call with nested select
1 parent 71342ba commit 3722aca

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public static IQueryable<TSource> Select<TSource>(this IQueryable<TSource> sourc
304304
private static IQueryable<TSource> CallGenericSelectMethod<TSource>(IQueryable<TSource> source, List<string> columns)
305305
{
306306
var sourceBindings = new List<MemberAssignment>();
307-
var sourceType = typeof(TSource);
307+
var sourceType = typeof(TSource);
308308
var parameter = Expression.Parameter(source.ElementType, "x");
309309
var sourceProperties = new List<string>() { };
310310

@@ -375,7 +375,7 @@ private static IQueryable<TSource> CallGenericSelectMethod<TSource>(IQueryable<T
375375
// {x.Owner.Name}
376376
var nestedBody = Expression.PropertyOrField(srcBody, nested);
377377
var propInfo = nestedPropertyType.GetProperty(nested);
378-
nestedBindings.Add(Expression.Bind(propInfo, nestedBody));
378+
nestedBindings.Add(Expression.Bind(propInfo, nestedBody));
379379
}
380380
// { new Owner() }
381381
var newExp = Expression.New(nestedPropertyType);
@@ -397,10 +397,10 @@ private static IQueryable<TSource> CallGenericSelectMethod<TSource>(IQueryable<T
397397

398398
var sourceInit = Expression.MemberInit(Expression.New(sourceType), sourceBindings);
399399
var finalBody = Expression.Lambda(sourceInit, parameter);
400-
400+
401401
return source.Provider.CreateQuery<TSource>(Expression.Call(
402-
typeof(Queryable),
403-
"Select", // It would be better to call generic IQueryable<TSource>.Select() method (FirstOrDefaultAsync can't be called on non-generic)
402+
typeof(Queryable),
403+
"Select",
404404
new[] { source.ElementType, typeof(TSource) },
405405
source.Expression,
406406
Expression.Quote(finalBody)));

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private async Task<TResource> GetWithRelationshipsAsync(TId id)
248248
});
249249

250250
TEntity value;
251-
// FirstOrDefaultAsync exprects Queryable<TEntity>, but CallGenericSelectMethod creates Queryable only
251+
// https://github.com/aspnet/EntityFrameworkCore/issues/6573
252252
if (_jsonApiContext.QuerySet?.Fields?.Count > 0)
253253
value = query.FirstOrDefault();
254254
else

0 commit comments

Comments
 (0)