-1
I’m a beginner in C# and I’m developing a CRUD using Angular and Web Api (Entity Framework Core), but the response time to list my Serverscontroller data in my table is very high. What happens nowadays is that it takes a long time to list only 48 records (more than 5 minutes or sometimes not even loads), talking to a colleague I was proposed to do the consultation in the direct bank in my Get method and consume the query by right there, the big question is: how can I consume this query? because the connection/instance of the database I was able to do. Follow the current code below:
[HttpGet]
public async Task<ActionResult<IEnumerable<Server>>> GetServer()
{
using (var context = new ITControlContext())
{
using (var command = context.Database.GetDbConnection().CreateCommand())
{
command.CommandText = "SELECT e.Name [Environment], t.Name [ServerType], p.Name [Plant] FROM [ITControl].[dbo].[Server] s INNER JOIN [ITControl].[dbo].[Environment] e on s.IdEnvironment = e.IdEnvironment INNER JOIN [ITControl].[dbo].[ServerType] t on s.IdServerType = t.IdServerType INNER JOIN [ITControl].[dbo].[Plant] p on s.IdPlant = p.IdPlant";
context.Database.OpenConnection();
System.Data.DataTable dataTable = new System.Data.DataTable();
dataTable.Load(command.ExecuteReader());
}
}
return await _context.Server.Include(i => i.IdEnvironmentNavigation).Include(i => i.IdServerTypeNavigation).Include(i => i.IdPlantNavigation).ToListAsync();
}
What I tried to do was create a "new instance" of my database and do the query there (I don’t know much what I did) and I would like to return the data of this query to be able to list them in my table without taking so long. Does anyone have any idea what I can do or give me any North of what to research/study?
Ps: I imagine I have to change something in mine return
pq has a select for a Datatable and then another in the Entity ? still you would have to see how is your bank, and exactly what point is there the delay
– Rovann Linhalis
the Entity I left pq is the one I was using before the colleague told me to do the Get query even, follow link like this in my bank
– Bruno Taletti
comments block using any...leaves only Entity line... still there is delay ? there just seeing bank, indices, etc...
– Rovann Linhalis
then, first with the Entity passing by
.Include(i => i.IdEnvironmentNavigation).Include(i => i.IdServerTypeNavigation).Include(i => i.IdPlantNavigation).ToListAsync();
in thereturn
He didn’t even present anything on the table and was that way,18 minutes charging and still nothing, now when I passed only 2 "Includes" EX:.Include(i => i.IdEnvironmentNavigation).Include(i => i.IdServerTypeNavigation).ToListAsync();
it took 0.58ms and presented only the 2 image here– Bruno Taletti
I commented using all and left only Entity as recommended above photo but he continues to consult eternally print table
– Bruno Taletti
Rovann would have some idea of what I could do or study to do this?
– Bruno Taletti
tries to run a request manually with Postman... to see if it’s in the api too right... but would need to see what was done in the bank, how is your relationship etc...
– Rovann Linhalis
I’ll do it now. I’ll have to talk to the team because I’m not the one who modeled the bank I’m an intern to suffering hahah
– Bruno Taletti
Rovann my noble, by Postman sent a request of type GET and he returned me: Status: 200 OK, Time: 506ms, Size: 847 B
– Bruno Taletti
500ms may even be time consuming depending on the scenario, but apparently the problem is not in the api...
– Rovann Linhalis
Would it be on the front? also imagined q n would be on the pq API if n it would return me error on the browser console
– Bruno Taletti
I’m doing with the angle code here at my service in part
prop
I’m pulling the values that were inreturn await _context
– Bruno Taletti
Apparently I found the error, I’m making the query in the database by GET but I’m not calling anything from datatable in Return, but checking otherwise (which makes my api weigh), apparently this is the problem, now I need to look how to return this datatable
– Bruno Taletti
as I said above, comment the block using all... do not use one
DataTable
...– Rovann Linhalis
I figured it out, I’ll post the answer
– Bruno Taletti