Sto provando a selezionare un elenco di numeri interi e sta generando un'eccezione.
Messaggio di eccezione: System.ArgumentException: espressione del tipo 'System.Collections.Generic.IAsyncEnumerable1 [System.Int32]' non può essere utilizzata per il parametro di tipo 'System.Collections.Generic.IAsyncEnumerable1 [System.Object]' del metodo 'System. Collections.Generic.IAsyncEnumerable1 [MyProject.Model.Entities.MyTable] CastModel 'Nome parametro: arg0
Modello
public class MyTable {
public int MyTableId { get; set; }
public int SomeKey { get; set; }
public int MyFieldIntegerIWant { get; set; }
}
Esegui la query qui sotto (o una simile):
int keyId;
var ids = await context.MyTable.AsNoTracking()
.Where(x => x.SomeKey.Equals(keyId))
.Select(x => x.MyFieldIntegerIWant)
.ToListAsync();
Versione EF Core: 1.1.0
Provider di database: Microsoft.EntityFrameworkCore.SqlServer
Sistema operativo: Windows 7
IDE: Visual Studio 2015
AGGIORNARE:
The issue had something to do with EF Plus' QueryFilters
https://github.com/zzzprojects/EntityFramework-Plus/issues/133
Dopo aver discusso con @thejason,
Il problema non è stato causato da Entity Framework Plus ma dal modo in cui l'EF Core gestisce il cast.
Il problema può essere facilmente riprodotto utilizzando il seguente codice:
using (var ctx = new CurrentContext())
{
int keyId = 1;
var ids = ctx.MyTables
.Cast<IMyTable>()
.Cast<MyTable>()
.Where(x => x.SomeKey.Equals(keyId))
.Select(x => x.MyFieldIntegerIWant)
.ToList();
}
Il metodo Cast verrà corretto in EF Core 2.x.