Reputation: 1999
I am calling a stored procedure from MVC 5 application with Entity Framework 6. It is throwing this error:
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'rv_test_param 1' at line 1
My code is:
var res = Context.Database.SqlQuery<string>("rv_test_param @id", new MySqlParameter("@id", 1)).ToList();
The stored procedure is working fine. If I call stop without parameters
Like this:
var redf = Context.Database.SqlQuery<string>("rv_test").ToList();
it also works fine. Does Anyone have an idea why it is not working with parameters?
Upvotes: 2
Views: 3843
Reputation: 536
You can do it another way, e.g:
db.Database.ExecuteSqlCommand("CALL GenarateTable(@tablename)", new MySqlParameter("@tablename", tenantDetail.tablename));
Upvotes: 0
Reputation: 1
DateTime CurrentDateStarts = (DateTime)dtBegin.Value;
DateTime CurrentDateEnds = (DateTime)dtEnd.Value;
CurrentDateStarts = (new DateTime(CurrentDateStarts.Year, CurrentDateStarts.Month, CurrentDateStarts.Day));
CurrentDateEnds = (new DateTime(CurrentDateEnds.Year, CurrentDateEnds.Month, CurrentDateEnds.Day)).AddDays(1).AddSeconds(-1);
//
geststokv1Entities2 con = geststokv1Entities2.newInstance;
var produit = cmbProduct.SelectedItem.ListObject as stock_produit;
var result = con.Database.SqlQuery<view_articleanalysis>("call get_articleanalysis(@produit_id)", new MySql.Data.MySqlClient.MySqlParameter("@produit_id", produit.PRODUIT_ID)).ToList();
var list = result.Where(x => x.FREE_QUANTITY > 0
&& x.Date_validation >= CurrentDateStarts
&& x.Date_validation <= CurrentDateEnds
).ToList();
UGFree.DataSource = list;
Upvotes: 0
Reputation: 1999
Syntax mistake. I'm from a SQL Server background, so I was not aware of these syntaxes. This is working for me:
var res = Context.Database.SqlQuery<string>("call rv_test_param(@id)", new MySqlParameter("@id", 1)).ToList();
Upvotes: 4