How to Count the Number of records in the Database Table using Asp.Net Core Entity Framework Core


Question: How do you get a Count of records in the Database Table using the Asp.Net Core Entity Framework Core?


Login to See the Rest of the Answer

Answer:
You can easily get the count of elements or records in the Database Table using Entity Framework by utilizing the CountAsync() function on the Database Context. Keep in mind the best practices of requesting data from the Database, always include a Where Clause. 

See the Code below for reference:

int count = await _context.YourModalClass.CountyAsync<YourModelClass>(a => a.YourPredicateComesInHere == YourValueCouldBeAnID).ConfigureAwait(false); 

 

[NB] The ConfigureAwait(false) tells the EF Core to run this query on a different thread and then notify the UI Thread when the query completes executing.







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]