Why does my raw query to count rows always returns -1?

后端 未结 2 337
醉话见心
醉话见心 2021-01-20 15:38

I\'m trying to check if table exists, but not working correctly.

For some reason, count always returns -1. I already have a table in the database. It should return

2条回答
  •  伪装坚强ぢ
    2021-01-20 15:54

    ExecuteSqlCommand doesn't return data, it always returns an Int32, which is the number of rows processed by the SQL script when it's a DDL/DML command.

    You want SqlQuery(String, Object[]) instead.

    var count = db.Database.SqlQuery(sql4).Single();
    

提交回复
热议问题