Skip to content

NHibernate async operations are not supported #35

Open
@gmcelhanon

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.

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