1

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.

2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

but that's not all. "exec" is not required and Customer should be passed as a parameter.
Thanks everyone. Removed the exec and changed the SqlRes's property to 'data', and now it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.