1

I am currently using Entity Framework 5 I've tried to code the following:

var result = context.Database.SqlQuery<Entity>("SELECT * FROM ref.Entity");

But I get the following error:

Specified method is not supported.

Can anyone show me a resolution to this issue?

stack trace

"at EFProviderWrapperToolkit.DbConnectionWrapper.CreateDbCommand()\r\n at System.Data.Common.DbConnection.CreateCommand()\r\n at System.Data.Objects.ObjectContext.CreateStoreCommand(String commandText, Object[] parameters)\r\n at System.Data.Objects.ObjectContext.ExecuteStoreQueryInternal[TElement](String commandText, String entitySetName, MergeOption mergeOption, Object[] parameters)\r\n at System.Data.Objects.ObjectContext.ExecuteStoreQuery[TElement](String commandText, Object[] parameters)\r\n at System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery[TElement](String sql, Object[] parameters)\r\n at System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerable[TElement](String sql, Object[] parameters)\r\n at System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Object[] parameters)\r\n at System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator()\r\n at System.Data.Entity.Internal.InternalSqlQuery1.GetEnumerator()\r\n at System.Linq.SystemCore_EnumerableDebugView1.get_Items()"

4
  • 1
    ref will be undefined ... SQL wont know what to do with that? Commented May 15, 2013 at 7:56
  • don't uderstand you comment, ExecuteSqlCommand() also return System.NotSupportedException Commented May 15, 2013 at 9:19
  • Can you post Exception stack trace Commented May 15, 2013 at 9:46
  • 1
    falls EFProviderWrapperToolkit. problem solved here Commented May 15, 2013 at 10:52

2 Answers 2

2

This is mentioned in "Known Problems" section on codeplex "Community Entity Framework Provider Wrappers" site. Citing:

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()
Sign up to request clarification or add additional context in comments.

Comments

1

The answer is quite simple. I am not sure if you have the source code of EFProviderWrapperToolkit, you should get it and have a look at it. You will notice that DbConnectionWrapper, which inherits from DbConnection it overrides CreateDbCommand method but does not provide any functionality for it, instead it throws and exception.

/// <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();
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.