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

NHibernate async operations are not supported #35

Open
gmcelhanon opened this issue Apr 3, 2021 · 3 comments
Open

NHibernate async operations are not supported #35

gmcelhanon opened this issue Apr 3, 2021 · 3 comments

Comments

@gmcelhanon
Copy link

When trying to use this library with code utilizing the new asynchronous support added to NHibernate 5, you will encounter the following exception:

System.InvalidCastException: Unable to cast object of type 'NHibernate.SqlAzure.ReliableSqlCommand' to type 'System.Data.SqlClient.SqlCommand'.
   at NHibernate.AdoNet.SqlClientBatchingBatcher.AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)

The source of the problem is that (previously) some of the NHibernate methods in the SqlClientBatchingBatcher class have been replaced (copy/paste/modify) in the ReliableSqlClientBatchingBatcher class with versions that handle the cast of the ReliableSqlCommand (which derives from DbCommand and not SqlCommand) appropriately.

With the new asynchronous methods in NHibernate here, the code that executes is once again the NHibernate version, and it tries to cast the command to a SqlCommand and the exception occurs.

I have fixed the problem locally in our code base by copying the new asynchronous methods in NHibernate down into the ReliableSqlClientBatchingBatcher class and followed the same pattern that was originally used on the synchronous implementation in this library.

I wanted to at least report the problem as it may help others who might encounter this issue. Given the low level of nuget downloads and maintenance activity on the project, I'm not sure a PR would be particularly useful here.

@robdmoore
Copy link
Member

robdmoore commented Apr 3, 2021 via email

@Will-Bill
Copy link

Hey @gmcelhanon could you do a PR for this change? I'd highly appreciate it.

@gmcelhanon
Copy link
Author

@Will-Bill Finally got around to this! PR opened: #38

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