Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'FromSql' or 'SqlQuery' was called with non-composable SQL and with a query composing over it

I have a simple stored procedure that I call the FromSqlRaw command.

db.Package.FromSqlRaw("EXEC dbo.sp_GetPackage").First();

In this case, get me the error that :

'FromSql' or 'SqlQuery' was called with non-composable SQL and with a query composing over it. Consider calling 'AsEnumerable' after the method to perform the composition on the client side.

Of course When I changed my code to :

db.Package.FromSqlRaw("EXEC dbo.sp_GetPackage").Tolist().First();

worked currently.

Actually, I should not use Tolist(). Can you help me?

like image 902
hmahdavi Avatar asked May 30 '26 10:05

hmahdavi


1 Answers

Check that you are not using HasQueryFilter in the entity

modelBuilder.Entity(type).HasQueryFilter(predicate);

If this is the case, use .IgnoreQueryFilters() and do this:

customStorage.Set<Group>().FromSqlRaw(sql, userId).IgnoreQueryFilters().ToListAsync()

Or await

_db.RoleRecursiveDtos.FromSqlInterpolated(prCommand).IgnoreQueryFilters().ToListAsync(cancellationToken);
like image 81
Emerson Stori Avatar answered Jun 02 '26 07:06

Emerson Stori