数据阅读器有多个字段.多个字段对EDM基元类型无效

Paw*_*iya 6 mysql linq executestorequery

我试图使用ExecuteStoreQuery像这样的linq 方法从表中删除多行

 string query = "delete from IMPORTStatistics where districtid='" + districtId + "'";
 db.ExecuteStoreQuery<int>(query);
Run Code Online (Sandbox Code Playgroud)

但它抛出了这个例外

"The data reader has more than one field. Multiple fields are not valid for EDM primitive types."
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

仅供参考,我使用的是MySql.

Jon*_*eet 10

鉴于您正在执行删除命令(而不是查询),我认为您应该使用ExecuteStoreCommand而不是ExecuteStoreQuery.

此外,您绝对应该使用参数而不是将ID直接放入命令中.

string command = "delete from IMPORTStatistics where districtid={0}";
int rowsDeleted = db.ExecuteStoreCommand(command, districtId);
Run Code Online (Sandbox Code Playgroud)