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

Non-Scalar Query in Dapper requires access to DbTransaction #7

Closed
gentoorax opened this issue Jan 15, 2024 · 0 comments · Fixed by #8
Closed

Non-Scalar Query in Dapper requires access to DbTransaction #7

gentoorax opened this issue Jan 15, 2024 · 0 comments · Fixed by #8
Assignees
Labels
bug Something isn't working

Comments

@gentoorax
Copy link
Owner

Attempting to perform a non-scalar query with Dapper in a transaction requires access to the transaction.

public IEnumerable<TestEntity> GetEntities()
{
    const string query = "SELECT * FROM TestEntity";
    return SqlConnection3.Query<TestEntity>(query);
}

The above will throw...

System.InvalidOperationException: ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized.

Modify the AdoContext to allow access to the transaction as required.

@gentoorax gentoorax added the bug Something isn't working label Jan 15, 2024
@gentoorax gentoorax self-assigned this Jan 15, 2024
gentoorax added a commit that referenced this issue Jan 17, 2024
* Create test to identify problem with Dapper non-scalar transactional reads.

* Expose transaction for use with Dapper

Note this transaction object should not be used to commit or rollback the transaction!

* Update ambient transaction get to return null when no transaction in bug #7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant