Where you have, ToListAsync(); , replace it with .AsNoTracking().ToListAsync();
That should help quite a bit.
Entity Framework very slow compared to SQL Query
Hi,
I have a Stored Procedure which returns the result within a second.
When I call the stored procedure from my Web API it takes at least 15 seconds to return the data. Sometimes goes upto few minutes.
I am using the below method. It returns around 15000 records with size around 2 MB.
public async Task<IEnumerable<Find>> GetFinds(int level)
{
var finds = _context.Finds.FromSqlRaw<Find>("sp_SHT_SelectAllValuesGivenLevels_Find {0}", level).ToListAsync();
return await finds;
}
Model:
[Keyless]
public class Find
{
[Column(TypeName="varchar")]
public string ID { get; set; }
[Column(TypeName="varchar")]
public string Description { get; set; }
}
DBContext:
public class PHTDbContext : DbContext
{
public PHTDbContext(DbContextOptions<PHTDbContext> options) : base(options)
{
}
public DbSet<Find> Finds { get; set; }
}
I am redesigning the application from ASP.Net WebForms to ASP.Net Core Web API + Angular.
The redesign should make the application faster but it is slowing down.
Please help me with this.
1 answer
Sort by: Most helpful
-
JD N 11 Reputation points
2022-12-07T20:30:24.697+00:00