<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz" -->

---
title: Enlisting an ADO.NET command in an NHibernate transaction
description: A technique is shown for running a raw SQL batch command (like a bulk DELETE) within an NHibernate-managed transaction, instead of fetching and deleting...
canonical: https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Enlisting an ADO.NET command in an NHibernate transaction | daily.dev
og:description: A technique is shown for running a raw SQL batch command (like a bulk DELETE) within an NHibernate-managed transaction, instead of fetching and deleting...
og:url: https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz
og:image: https://api.daily.dev/og/posts/iO4dHTKmz.png
og:image:alt: Enlisting an ADO.NET command in an NHibernate transaction
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Enlisting an ADO.NET command in an NHibernate transaction

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 1 min read · 0 upvotes · 0 comments

## Summary

A technique is shown for running a raw SQL batch command (like a bulk DELETE) within an NHibernate-managed transaction, instead of fetching and deleting entities one by one. Building on an earlier blog post by jlockwood, the approach creates an ADO.NET IDbCommand from the NHibernate session's connection, enlists it into the active NHibernate transaction, and executes the raw SQL, with an improved, provider-independent version of the original code provided.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2007-06-20-enlisting-an-ado-net-command-in-an-nhibernate-transaction>

## Questions this post answers

### How do I run a raw SQL batch delete inside an NHibernate transaction?

Create an IDbCommand from the NHibernate session's connection, call transaction.Enlist(command) to enlist it into the active NHibernate transaction, set the CommandText to the raw SQL, then call ExecuteNonQuery and commit the transaction. This avoids fetching and deleting entities one at a time and works across database providers since it relies on the session's own connection rather than a hardcoded connection string.

_daily.dev surfaces practical NHibernate and ADO.NET transaction patterns like this for developers optimizing data layer code._

## Similar posts on daily.dev

- [SQL Server Bulk Delete Batches](https://daily.dev/posts/sql-server-bulk-delete-batches-xs69je9hx) · Medium · 0 upvotes · 0 comments
- [Insane Performance Boost in EF Core using Entity Framework Extensions](https://daily.dev/posts/insane-performance-boost-in-ef-core-using-entity-framework-extensions-r3pbiriw6) · We Are .NET · 4 upvotes · 0 comments
- [Milan Jovanović](https://daily.dev/posts/milan-jovanovi--lmrqyshnk) · Milan Jovanović · 2 upvotes · 0 comments

---

Tags: [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Enlisting an ADO.NET command in an NHibernate transaction","url":"https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz"},"datePublished":"2026-10-04T13:06:41.961Z","dateModified":"2026-10-04T13:18:25.977Z","description":"A technique is shown for running a raw SQL batch command (like a bulk DELETE) within an NHibernate-managed transaction, instead of fetching and deleting...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c905471c3def16ba4b2bc3f60cf9dbd2?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c905471c3def16ba4b2bc3f60cf9dbd2?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c#","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"Enlisting an ADO.NET command in an NHibernate transaction"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/enlisting-an-ado-net-command-in-an-nhibernate-transaction-io4dhtkmz#faq","mainEntity":[{"@type":"Question","name":"How do I run a raw SQL batch delete inside an NHibernate transaction?","acceptedAnswer":{"@type":"Answer","text":"Create an IDbCommand from the NHibernate session's connection, call transaction.Enlist(command) to enlist it into the active NHibernate transaction, set the CommandText to the raw SQL, then call ExecuteNonQuery and commit the transaction. This avoids fetching and deleting entities one at a time and works across database providers since it relies on the session's own connection rather than a hardcoded connection string. daily.dev surfaces practical NHibernate and ADO.NET transaction patterns like this for developers optimizing data layer code."}}]}
```

