Search code examples
c#mysqlentity-framework-coreef-code-first

Entity Framework Core counting tables and records Code-First Approach (MySQL)


I've started using Entity Framework Core with Code-First approach and currently I'm not very used to it. My Entity Framework Core version is 3.1.20.

Q: How to check how many tables available in some specific database?

Q: How to get the total record count in some specific database?

Q: How to get the total record count in some specific table?


Solution

  • Q: How to check how many tables available in some specific database?

    Check this answer

    Q: How to get the total record count in some specific database?

    This answer may help

    var tablesinfo = ctx.GetTablesInfo();
    var totalRecordCount = tablesinfo
        .IgnoreQueryFilters()
        .Sum(ti => ti.RecordCount);
    

    Q: How to get the total record count in some specific table?

    var recordCount = ctx.SomeTable.Count();