6

我正在尝试使用ExecuteStoreQuery这样的 linq 方法从表中删除多行

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

但它抛出了这个异常

"The data reader has more than one field. Multiple fields are not valid for EDM primitive types."

我究竟做错了什么?

仅供参考,我正在使用 MySql。

4

2 回答 2

10

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

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

string command = "delete from IMPORTStatistics where districtid={0}";
int rowsDeleted = db.ExecuteStoreCommand(command, districtId);
于 2013-01-25T11:16:24.293 回答
0

This is really helpful link after goggling I found this

http://welcometoaspdotnet.blogspot.com/2012/08/execute-stored-procedure-with-entity.html

thx

于 2014-04-01T14:10:30.960 回答