简体   繁体   中英

Getting table size using Entity Framework

I am using EF6 and I am trying to get the table sizes. I believe this should work but the result comes back as zero:

public class SqlRes{
    public int Size { get; set; }
}

var size = DbContext.Database.SqlQuery<SqlRes>("exec sp_spaceused Customer").ToList();

I have also tried to use type like string or int with no success. Please help.

The property names of SqlRes should match the column names returned by the stored procedure.

According to SQL Docs , the column names are:

  • name
  • rows
  • reserved
  • data
  • index_size
  • unused

Try changing your SqlRes class to have those property names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM