Stackedup
Stackedup

Reputation: 760

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.

Upvotes: 1

Views: 1475

Answers (1)

Rowan Freeman
Rowan Freeman

Reputation: 16358

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.

Upvotes: 1

Related Questions