I am using EF 6 with MVC5/C#
I am trying to run an insert statement, using SqlParameter objects, via ExecuteStoreCommand over EF. I am doing it this way as I have some performance issues with AddObject.
My code is:
string insertCmd = "INSERT INTO TABLE (Value,FkId) VALUES (@Value,@FkId)";
var paramList = new[]{
new SqlParameter("@Value", SqlDbType.VarChar).Value = value,
new SqlParameter("@FkId", SqlDbType.Int).Value = fkId
};
db.ExecuteStoreCommand(insertCmd, paramList);
I am getting the error:
Must declare the scalar variable "@Value". Statement(s) could not be prepared.
I have noticed that it always complains about the first column in the Insert statement regardless of type. So if I swapped it around I would get:
Must declare the scalar variable "@FkId". Statement(s) could not be prepared.
Thoughts ?
EDIT:
Just noticed that the record gets inserted and saved to the DB, yet I still get this error. Puzzled...