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
I have tried this code and throws System.InvalidOperationException on result2 variable.
class Program
{
static void Main(string[] args)
{
using (var ctx = new TestContext())
{
if (ctx.Database.EnsureCreated())
{
for (int i = 0; i < 100; i++)
{
ctx.Add(new Entity());
}
ctx.SaveChanges();
}
var result = ctx.Entities.OfType<IEntity>().ToArray().Select(e => e.Id); //Works
var result2 = ctx.Entities.OfType<IEntity>().Select(e => e.Id).ToArray(); //Fails
}
}
}
public class TestContext : DbContext
{
public DbSet<Entity> Entities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=test.db");
}
}
public class Entity : IEntity
{
public int Id { get; set; }
}
public interface IEntity
{
int Id { get; set; }
}
Error Detail
System.InvalidOperationException
HResult=0x80131509
Message=The query model's result type cannot be changed to 'System.Linq.IQueryable1[System.Int32]'. The result type may only be overridden and set to values compatible with the ResultOperators' current data type ('System.Linq.IQueryable1[TestQuery.IEntity]').
Source=Remotion.Linq
StackTrace
at Remotion.Linq.QueryModel.GetOutputDataInfo()
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.IsTrackingQuery(QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger1 logger, Type contextType) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_01.b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Remotion.Linq.QueryableBase1.GetEnumerator()
at System.Collections.Generic.LargeArrayBuilder1.AddRange(IEnumerable1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at TestQuery.Program.Main(String[] args) in C:\Users\User\Projects\TestQuery\Program.cs:line 23
Inner Exception 1:
ArgumentException: 'System.Linq.IQueryable`1[System.Int32]' cannot be used as the data type for a sequence with an ItemExpression of type 'TestQuery.IEntity'.
Arg_ParamName_Name
Further technical details
EF Core version: 2.2.1
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Frameworks: .Net Core 2.2 and .Net Framework 4.7.2
Operating system: Windows 10 Pro Version 10.0.17763 Build 17763
IDE: Visual Studio 2017 15.9.5
The text was updated successfully, but these errors were encountered:
I have tried this code and throws System.InvalidOperationException on result2 variable.
Error Detail
System.InvalidOperationException
HResult=0x80131509
Message=The query model's result type cannot be changed to 'System.Linq.IQueryable
1[System.Int32]'. The result type may only be overridden and set to values compatible with the ResultOperators' current data type ('System.Linq.IQueryable
1[TestQuery.IEntity]').Source=Remotion.Linq
StackTrace
at Remotion.Linq.QueryModel.GetOutputDataInfo()
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.IsTrackingQuery(QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger
1 logger, Type contextType) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0
1.b__0()at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func
1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Remotion.Linq.QueryableBase
1.GetEnumerator()at System.Collections.Generic.LargeArrayBuilder
1.AddRange(IEnumerable
1 items)at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at TestQuery.Program.Main(String[] args) in C:\Users\User\Projects\TestQuery\Program.cs:line 23
Inner Exception 1:
ArgumentException: 'System.Linq.IQueryable`1[System.Int32]' cannot be used as the data type for a sequence with an ItemExpression of type 'TestQuery.IEntity'.
Arg_ParamName_Name
Further technical details
EF Core version: 2.2.1
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Frameworks: .Net Core 2.2 and .Net Framework 4.7.2
Operating system: Windows 10 Pro Version 10.0.17763 Build 17763
IDE: Visual Studio 2017 15.9.5
The text was updated successfully, but these errors were encountered: