I'm trying to call a stored procedure to retrieve a single record using EF Core but I keep getting the exception:
System.InvalidOperationException: 'FromSqlRaw or FromSqlInterpolated was called with non-composable SQL and with a query composing over it. Consider calling AsEnumerable after the FromSqlRaw or FromSqlInterpolated method to perform the composition on the client side.'
Here: ef-core-3.0 breaking-changes it is recommended to use use .AsEnumerable() but it has no effect. I don't see why it thinks I'm trying to compose over this SQL code:
var result = context.Set<TicketDetails>()
.FromSqlInterpolated($"EXECUTE GetTicket @TicketId = {id}")
.AsEnumerable()
.FirstOrDefault();
Also here is a similar issue that didn't give a solution for me.
I'm using a different mechanism that does work - so you can return one or more rows into a C# class
Here is my DB Set of the stored proc
Here is the code that returns a list but you would replace the last part with FirstOrDefaultAsync. You MUST ensure that the parameters are in the same order as the SQL despite creating them named - the DBContext code just ignores that. You can also set parameters in SQL such as @Sort=@Sort which does work by matching names rather than order