1

Hi I'm trying to execute stored procedure using entity framework like below.

var empid = new SqlParameter("@empid", "E001");
                    var dept = new SqlParameter("@dept", "D001");

                    var selectData = dbContext.ExecuteStoreQuery<EmpDO>("getEmployeeDetails @empid, @deptid", empid, deptid);

When I try to run my application, I'm getting below error. Any idea?

enter image description here

jestges
  • 3,686
  • 24
  • 59
  • 95

2 Answers2

2

Is this a Typo? The variable is dept, but the variable used in the function call is deptid. Code is changed below.

var empid = new SqlParameter("@empid", "E001");
var dept = new SqlParameter("@dept", "D001");

var selectData = dbContext.ExecuteStoreQuery<EmpDO>("getEmployeeDetails @empid, @deptid", empid, dept);

I just looked on the community site and they have...

Known Problems

Directly executing store commands using methods such as ObjectContext.ExecuteStoreCommand or ObjectContext.ExecuteStoreQuery is not supported. You may, however, create a DbCommand from the database connection using code such as this:

using EFProviderWrapperToolkit;
...
context.Connection.GetStoreConnection().CreateCommand()
Christian Phillips
  • 18,399
  • 8
  • 53
  • 82
0

Take a look at the link below for a question asked previously. Unless the method is now implemented in the EFPrivderWrapperToolkit, this should answer your question as to why you are getting the error. The DbCommand method is overridden by the toolkit but not implemented.

/// <summary>
        /// Creates and returns a <see cref="T:System.Data.Common.DbCommand"/> object associated with the current connection.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Data.Common.DbCommand"/> object.
        /// </returns>
        protected override DbCommand CreateDbCommand()
        {
            throw new NotSupportedException();
        }

Similar StackOverflow Question

Community
  • 1
  • 1
LeftyCoder
  • 432
  • 1
  • 5
  • 10