Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8393313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:45:01+00:00 2026-06-09T19:45:01+00:00

We are using the Enterprise Library as a standard DAL. Now, I would like

  • 0

We are using the Enterprise Library as a standard DAL. Now, I would like to enjoy the benefits of Dapper. Looking at the implementation it is just extending the connection class.

Is it conceivable to set Dapper to extend Enterprise Library so we can enjoy both worlds?
Or maybe someone already created this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:45:03+00:00Added an answer on June 9, 2026 at 7:45 pm

    Yes, it is conceivable, and it works pretty well. We’re using Dapper to supplement some older EntLib code, and simple queries are quick and painless. The biggest challenge was getting Transactions to work properly. You don’t mention which version of EntLib you are using, but 4.0 and newer manage connections inside of TransactionScopes, so if you try to open another connection for Dapper inside of a scope with EntLib it will automatically escalate from a lightweight local transaction to DTC (Distributed Transaction Coordinator). EntLib doesn’t really provide a way to grab the current open connection, so you have to derive from the Database class and expose the GetOpenConnection method.

    public class EntLibDatabaseWrapper : Database
    {
        // ...Constructor and overrides...
    
        public IDbConnection GetMyOpenConnection()
        {
            var connectionWrapper = GetOpenConnection();
            return connectionWrapper.Connection;
        }
    }
    

    Then use it something like this:

    var db = DatabaseFactory.CreateDatabase();
    var dbWrapper = new EntLibDatabaseWrapper(db.ConnectionString, db.DbProviderFactory);
    
    using (var scope = new TransactionScope())
    {
        var connection = dbWrapper.GetMyOpenConnection();
    
        try
        {
            // Insert a test value using dapper
            var fooId = 
                connection.Query<int>("insert into Foo values (name = @name); select cast(scope_identity() as int", 
                                        new { name = "Foo" }).Single();
            // Insert a test value using Enterprise Library
            var cmd =
                db.GetSqlStringCommand(
                    "insert into Foo values (name = 'Bar'); select cast(scope_identity() as int)");
            var barId = int.Parse(db.ExecuteScalar(cmd));
            scope.Complete();
        }
        catch (Exception)
        {
            connection.Close();
            throw;
        }
    }
    

    If you have larger transaction scopes then you have to check to see if you are in an active transaction before you close each connection.

    if(Transaction.Current == null)
         connection.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a console application using Enterprise Library my code is something like
I am using Enterprise Library 5.0, a tool to manage cross-cutting concerns like logging
I am using Enterprise Library 5, set up the Database successfully but am now
I've started using Enterprise Library and have the following questions: 1)How do I add
I'm using Enterprise library, but the idea is the same. I have a SqlStringCommand
I am using Enterprise Library 5.0 configuration tool from within VS2010. Every time I
Does anybody using latest enterprise library 4.1 in mono? I used mono migration analyzer
I am using the patterns & practices enterprise library (p&p EntLib) logging block to
I'm attempting to use the DatabaseFactory method from the Microsoft Enterprise Library. using Microsoft.Practices.EnterpriseLibrary.Data;
Using Enterprise Library 3.1, I have a logger that, once it reaches its rollSizeKB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.