Is it possible to use EF Core's DbSet<>.FromSqlRaw along with ToLinqToDB()?
See original GitHub issueI have an application that bases some result sets on raw SQL queries for an entity. The IQueryable returned from DbSet<>.FromSqlRaw(“select * from tablename”) for example fails when attempting to enumerate the IQueryable then returned from ToLinqToDB(). Is this situation supported? I was hoping it would use a subquery to apply the additional filters added by users of the IQueryable returned from ToLinqToDB().
I’m using linq2db.EntityFrameworkCore 2.0.5, linq2db 2.9.7, EFCore 3.1.3 against SQL Server 2017.
I receive the following exception and stack trace:
The method or operation is not implemented.
at Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSqlOnQueryable[TEntity](IQueryable`1 source, String sql, Object[] parameters)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.<>c__DisplayClass35_0.<TransformExpression>g__LocalTransform|2(Expression e)
at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.<>c__DisplayClass35_0.<TransformExpression>b__3(Expression e)
at LinqToDB.Expressions.Extensions.Transform(Expression expr, Func`2 func)
at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsImplDefault.TransformExpression(Expression expression, IDataContext dc, DbContext ctx, IModel model)
at LinqToDB.EntityFrameworkCore.LinqToDBForEFTools.TransformExpression(Expression expression, IDataContext dc, DbContext ctx, IModel model)
at LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsDataContext.ProcessExpression(Expression expression)
at LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr)
at LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache)
at LinqToDB.Linq.ExpressionQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at LinqToDB.EntityFrameworkCore.Internal.LinqToDBForEFQueryProvider`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Redacted.HealthCheckController.Get() in C:\redacted\HealthCheckController.cs:line 36
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext()
I’m calling a method on my data context that does the following:
public virtual IQueryable<CapacityData> GetRunsReport()
{
return CapacityRows.FromSqlRaw("select * from API_CapacityData_t where ProcessUnitCode IN (200, 201, 202, 203, 204, 205, 206)");
}
and then, and an example, doing this with that context:
_dc.GetRunsReport().ToLinqToDB().ToList();
I understand this scenario might not be intended as supported, but in the case it is supposed to be handled, I’m opening this issue.
Thank you!
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
Thank you for this guidance. I was able to make my change in a custom override of TransformExpression!
Will find time to convert
FromSqlRaw
. We have our ownFromSql
method. Just forgot to create transformation.