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

StackOverflow https://stackoverflow.com/questions/14520627

  •  05-03-2022
  •  | 
  •  

Question

I am trying to delete multiple rows from the table using linq's ExecuteStoreQuery method like this

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

but it is throwing this exception

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

What am I doing wrong?

Just for the information, I am using MySql.

Was it helpful?

Solution

Given that you're executing a delete command (not a query), I think you should be using ExecuteStoreCommand instead of ExecuteStoreQuery.

Additionally, you should definitely be using parameters instead of putting the ID directly into the command.

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

OTHER TIPS

This is really helpful link after goggling I found this

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

thx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top