Tengo un gran conjunto de datos que estoy tratando de ejecutar pero estoy experimentando el siguiente error;
Statement(s) could not be prepared.
Seguimiento de pila
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
at Microsoft.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at Microsoft.Data.SqlClient.SqlDataReader.Read()
at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Read()
at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at SalesForceReportSVC.Controllers.SalesForceDataLoaderController.<GetSDL>d__6.MoveNext() in C:\Users\JNyingi\source\repos\SalesForceReportSVC\SalesForceReportSVC\Controllers\SalesForceDataLoaderController.cs:line 60
La excepción se produce en la siguiente declaración
IQueryable<SalesForceProductionReportDto> dLProductions = this.repo_.salesforceLoader.FindAll();
IEnumerable<SalesForceProductionReportDto> reportDtos = dLProductions.ToList();
Repositorio
public IQueryable<SalesForceProductionReportDto> FindAll()
{
return this.salesForceReport.Set<SalesForceProductionReportDto>().AsNoTracking();
}
Contexto
private void ConfigureAPIIntegrations(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(this.APIdb, opt => opt.CommandTimeout((int)TimeSpan.FromMinutes(20).TotalSeconds));
optionsBuilder.EnableDetailedErrors();
}
Quiero que ToList
implemente y cargue datos de la base de datos.
EDITAR
Incluso una simple consulta Linq como esta;
List<SalesForceProductionReportDto> salesForces = this.salesForceReport.productionReports.Select(x => x).ToList();
Me lleva mucho tiempo ejecutarlo, pero puedo ejecutar una instrucción SELECT
para más de 15000 registros en menos de 1 segundo.
EDITAR 2
Estoy seleccionando desde una vista como se muestra en Context
public virtual DbSet<SalesForceProductionReportDto> productionReports { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SalesForceProductionReportDto>().HasNoKey() .ToView("DailyProductionReport_Vw");
base.OnModelCreating(modelBuilder);
}
Si bien no he recibido una razón de por qué no funciona.
Encontré un paseo al problema anterior, usando FromSqlRaw
Entonces la siguiente línea está funcionando;
List<SalesForceProductionReportDto> salesForces = this.salesForceReport.Set<SalesForceProductionReportDto>().FromSqlRaw<SalesForceProductionReportDto>("SELECT * FROM dbo.ProductionData_Vw;").ToList();