0

I am trying to run a stored procedure on MySQL with the below code :

List<SqlParameter> parms = new List<SqlParameter> {
                    new SqlParameter { ParameterName = "@word", Value = word }
                };
                Object result = _context.History.FromSqlRaw<HistoryDM>("EXEC GETHISTORY", parms.ToArray());
                if (result != null)
                {
                    retval = (IEnumerable<HistoryDM>)result;
                }

The error I get is : 'DbSet' does not contain a definition for 'FromSqlRaw' and no accessible extension method 'FromSqlRaw' accepting a first argument of type 'DbSet' could be found (are you missing a using directive or an assembly reference?). In fact I don't see any From* methods on that context.

I have no clue what is happening here. after some research, I also added the package "Microsoft.EntityFrameworkCore.Relational" but it did not have remove the error.

Thanks for your help in advance, UU

mohammad asghari
  • 1,817
  • 1
  • 16
  • 23
GeoSystems
  • 35
  • 7
  • Looks like an [extension method](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationalqueryableextensions.fromsqlraw?view=efcore-5.0) Did you add the package and the [correct using statement](https://stackoverflow.com/questions/51017703/error-cs1061-dbsett-does-not-contain-a-definition-for-fromsql-and-no-exte)? – Nikki9696 Apr 20 '21 at 17:29
  • I would have sworn that I had "using Microsoft.EntityFrameworkCore;" but reality was different :) Thanks @Mohammed. Now this throws a MySqlException "Only MySQL parameter objects may be stored". Any clue : if (word != null && !word.Equals("")) { var param = new SqlParameter("@word", word); var result = _context.History.FromSqlRaw("CALL GETHISTORY @word", param).ToList(); if (result != null) { retval = (IEnumerable)result; } } – GeoSystems Apr 20 '21 at 22:55
  • I created a new thread here for the follow-up issue : https://stackoverflow.com/questions/67190000/calling-mysql-stored-procedure-from-net-db-context-throws-only-mysqlparameter- @Muhammed can I credit you for your answer ? – GeoSystems Apr 21 '21 at 05:56

0 Answers0