You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UseConnectionPaging on a nested EF collection fails: LINQ expression could not be translated #574
Field 'actor' - The LINQ expression 'edgeNode => ...' could not be translated.
The test models in EntityGraphQL.EF.Tests (SQLite) are enough to reproduce it. The offset paging version of this bug is fixed in #573.
Cause
There are two problems, and fixing the first one exposes the second.
ConnectionEdgeExtension pages the edges with EntityGraphQL's own EnumerableExtensions.Skip/Take(int?). A nested collection depends on the parent row and is part of the parent's projection, so EF has to translate the call, and it doesn't know these helpers. On a root field this is fine, because EF evaluates the call before translating. Fix UseOffsetPaging on a nested EF collection #573 fixes this for offset paging by using System.Linq's Skip/Take when the collection isn't an IQueryable.
Applying that same change here gets past the first error, but the query then fails with The LINQ expression 'newEdgeParam ...' could not be translated. ProcessExpressionSelection wraps the edge Select in ConnectionHelper.ApplyCursors(...), which assigns cursors while enumerating in memory. That works for a root field, where that call is what runs the DB query. In a nested projection EF has to translate it, and it can't.
So nested connection paging needs cursors built in a way EF can translate (or added after the query runs), not just the Skip/Take change.
Workaround
Expose the collection as a root query field that takes the parent id, and page that instead.
Problem
UseConnectionPaging()on a field that is not on the root query type fails when its collection comes from EF, for example a navigation property:{ actor(id: 1) { movies(first: 1) { totalCount edges { node { name } } } } }The test models in
EntityGraphQL.EF.Tests(SQLite) are enough to reproduce it. The offset paging version of this bug is fixed in #573.Cause
There are two problems, and fixing the first one exposes the second.
ConnectionEdgeExtensionpages the edges with EntityGraphQL's ownEnumerableExtensions.Skip/Take(int?). A nested collection depends on the parent row and is part of the parent's projection, so EF has to translate the call, and it doesn't know these helpers. On a root field this is fine, because EF evaluates the call before translating. Fix UseOffsetPaging on a nested EF collection #573 fixes this for offset paging by usingSystem.Linq'sSkip/Takewhen the collection isn't anIQueryable.The LINQ expression 'newEdgeParam ...' could not be translated.ProcessExpressionSelectionwraps the edgeSelectinConnectionHelper.ApplyCursors(...), which assigns cursors while enumerating in memory. That works for a root field, where that call is what runs the DB query. In a nested projection EF has to translate it, and it can't.So nested connection paging needs cursors built in a way EF can translate (or added after the query runs), not just the Skip/Take change.
Workaround
Expose the collection as a root query field that takes the parent id, and page that instead.