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

  • SEARCH
  • Home
  • 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 7961751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:08:16+00:00 2026-06-04T05:08:16+00:00

With PetaPoco, how should I handle the creation of the Database class? My application

  • 0

With PetaPoco, how should I handle the creation of the Database class? My application will probably be making use of various repositories (not quite the DDD repository, more like a gateway repository) to encapsulate the queries.

Since I’ll have multiple repositories that need to access the same database connection, I was thinking of making a base class that created the Database class in the constructor and calls Dispose in its destructor, and simply call this object in all derived classes, so I think I would not need a using block in this scenario (since when the class goes out of scope it will close the database itself).

I also considered just creating the database object in the global.axax, on the Application_BeginRequest method so it’s available on every page, but I’m not entirely sure how that works (I think I’d need some kind of DatabaseManager class that instantiates it? I’ve only seen this approach used with things like NHibernate and RavenDB) and that seems to push the usage of the database object to the ASPX page itself instead of via a repository/data layer class, which seems smelly.

Any suggestions which of these approaches, if any, will work best? I’ve also seen that PetaPoco supports a “shared connection” so is that something I want to look at as well to minimize the number of open connections to the database?

  • 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-04T05:08:17+00:00Added an answer on June 4, 2026 at 5:08 am

    I usually create one Database per request. It is a lightweight object. Either in an ActionFilter use a Controller base class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list objects I use to fill using Petapoco. The class properties
I need to create a DAL and repositories using petapoco. The difficulty that comes
I'm using C# with TSQL and SQL Server 2005 I'm trying to use PetaPoco
I am trying PetaPoco with my Asp.Net Project. How can I use PetaPoco with
This is puzzling me. I'm using PetaPoco to retreive some values from a database,
I have the following POCO's: [PetaPoco.TableName(Customer)] [PetaPoco.PrimaryKey(ID)] public class User { [Required(ErrorMessage = Please
I am new to PetaPoco ORM in .net and i found it quite confused
Our current application uses a smart object style for working with the database. We
I am using PetaPoco Micro-ORM with my ASP.NET 4.0 project. PetaPoco T4 template (Database.tt)
I am using PetaPoco.Core 4.0.3 in a C# app to access a MySql database.

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.