-2

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?

  • None of these queries seem to be really compatible with a typical use of entity framework; in the context of EF the answers would be "1) it doesn't matter, because you query what you have modeled and if a modeled table is unavailable you have a problem." "2) it doesn't make sense to ask, because EF is only concerned with those tables it knows about" and "3) it doesn't really make sense to ask, but you can ask eg `context.Users.Count()`" – Caius Jard Nov 12 '21 at 08:44

1 Answers1

1

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();
Svyatoslav Danyliv
  • 21,911
  • 3
  • 16
  • 32