У меня есть огромный набор данных, который я пытаюсь выполнить, но у меня возникает следующая ошибка:
Statement(s) could not be prepared.
Трассировка стека
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
Исключение выдается при следующем утверждении
IQueryable<SalesForceProductionReportDto> dLProductions = this.repo_.salesforceLoader.FindAll();
IEnumerable<SalesForceProductionReportDto> reportDtos = dLProductions.ToList();
Репозиторий
public IQueryable<SalesForceProductionReportDto> FindAll()
{
return this.salesForceReport.Set<SalesForceProductionReportDto>().AsNoTracking();
}
Контекст
private void ConfigureAPIIntegrations(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(this.APIdb, opt => opt.CommandTimeout((int)TimeSpan.FromMinutes(20).TotalSeconds));
optionsBuilder.EnableDetailedErrors();
}
I хотите, чтобы ToList
реализовывал и загружал данные из базы данных.
EDIT
Даже простой запрос Linq, подобный этому;
List<SalesForceProductionReportDto> salesForces = this.salesForceReport.productionReports.Select(x => x).ToList();
Выполнение занимает много времени, но я могу выполнить оператор SELECT
для 15000 записей плюс менее чем за 1 сек c.
РЕДАКТИРОВАТЬ 2
I выбираю из вида, как показано в Context
public virtual DbSet<SalesForceProductionReportDto> productionReports { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SalesForceProductionReportDto>().HasNoKey() .ToView("DailyProductionReport_Vw");
base.OnModelCreating(modelBuilder);
}