Skip to content

NHibernate async operations are not supported #35

Open

Description

@gmcelhanon

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.

Activity

  1. robdmoore commented on Apr 3, 2021

    @robdmoore
    Member
  2. Will-Bill commented on May 21, 2021

    @Will-Bill

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

  3. gmcelhanon commented on Jul 11, 2021

    @gmcelhanon
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions