Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExecuteStoreQueryAsync fails with System.ArgumentException #6503

Closed
micktion opened this issue Sep 9, 2016 · 1 comment
Closed

ExecuteStoreQueryAsync fails with System.ArgumentException #6503

micktion opened this issue Sep 9, 2016 · 1 comment

Comments

@micktion
Copy link

micktion commented Sep 9, 2016

I'm not sure if you're taking 6.1.3 issues or if this is an issue in EF 7. I'll detail what I found as per your template...

Steps to reproduce

Pass MergeOption in place of ExecutionOptions

The issue

Fails with System.ArgumentException: No mapping exists from object type System.Data.IDataParameter[] to a known managed provider native type.

Exception message: System.ArgumentException: No mapping exists from object type System.Data.IDataParameter[] to a known managed provider native type.

Stack trace:
at System.Data.SqlClient.SqlCommand.<>c.b__167_0(Task1 result) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.Core.Objects.ObjectContext.d__6f1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult()
at System.Data.Entity.Core.Objects.ObjectContext.d__3d1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<ExecuteAsyncImplementation>d__91.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult() at System.Data.Entity.Core.Objects.ObjectContext.<ExecuteStoreQueryReliablyAsync>d__6c1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Tonic.Oms.Api.Tests.CoreTests.d__25.MoveNext() in E:\Projects\oms-platform\Tonic.Oms.Api\Tonic.Oms.Api.Tests\CoreTests.cs:line 432
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

Further technical details

The code that reproduces this issue is...

IDataParameter[] parameters = new IDataParameter[] {
    repository.CreateStoreQueryParameter("@LogonId", logonId),
    repository.CreateStoreQueryParameter("@Password", password),
    repository.CreateStoreQueryParameter("@status", status)};

var list = await repository.ModelObjectContext.ExecuteStoreQueryAsync<UserPasswordEntity>(
            commandText,
            MergeOption.AppendOnly,
            parameters);

Now it took me an afternoon to notice as this code compiles, runs then fails with a run time error, but the 2nd parameter should actually be of type ExecutionOptions and not a MergeOption enum. I don't know how this compiles, but it does, I'm guessing somewhere out there is an explicit cast operator from MergeOption to ExecutionOptions.

So when you pass ExecutionOptions it executes successfully...

ExecutionOptions options = new ExecutionOptions(MergeOption.AppendOnly);

IDataParameter[] parameters = new IDataParameter[] {
    repository.CreateStoreQueryParameter("@LogonId", logonId),
    repository.CreateStoreQueryParameter("@Password", password),
    repository.CreateStoreQueryParameter("@status", status)};

var list = await repository.ModelObjectContext.ExecuteStoreQueryAsync<UserPasswordEntity>(
            commandText,
            options,
            parameters);

I came across this error converting synchronous code to async. There is a synchronous method which takes MergeOption as a parameter.

EF version: 6.1.3
Operating system: Windows 10
Visual Studio version: VS 2015

Other details about my project setup:

@divega
Copy link
Contributor

divega commented Sep 10, 2016

This issue was moved to dotnet/ef6#59

@divega divega closed this as completed Sep 10, 2016
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants