GithubHelp home page GithubHelp logo

ony19161 / dbmanager Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 93 KB

A .net core library to manage (rdms - like MS Sql Server, MySql, PostgreSQL) db connections and handle db queries.

License: MIT License

C# 97.75% TSQL 2.25%

dbmanager's Introduction

Simplify Your .NET Project with DbManager

DbManager is a powerful package that simplifies the integration of CRUD (Create, Read, Update, Delete) operations in your .NET projects. It seamlessly supports various database systems like MS SQL Server, MySQL, and leverages the functionalities of Entity Framework Core.

Getting Started

Integrating DbManager into your project is as easy as 1-2-3-4:

Step 1: Add Project Reference

Begin by adding DbManager to your solution as a project reference.

  • .Net CLI

    dotnet add package DbManager.EFCore
    
  • Package Manager

    Install-Package DbManager.EFCore
    

Step 2: Register Database Context

In your Program.cs file, register the AppDbContext class of DbManager library:

var builder = WebApplication.CreateBuilder(args);

// Use DbManager -> AppDbContext to register DbContext for your project.
builder.Services.AddDbContext<AppDbContext>();

var app = builder.Build();

Step 3: Configure Connection Strings

In your appsettings.json file, configure the connection strings based on your database provider and entities project:

For MS SQL Server:

{
  "DatabaseProvider": "SqlServer", 
  "EntitiesAssemblyName": "Demo.Db", // Assembly name where you have your Entity classes
  "ConnectionStrings": {
     "DefaultConnection": "your_sql_server_connection_string_here"
  }
}

For MySQL:

{
  "DatabaseProvider": "MySql",
  "EntitiesAssemblyName": "Demo.Db",
  "ConnectionStrings": {
     "DefaultConnection": "your_mysql_connection_string_here"
  }
}

Step 5: Add entity class/classes

[Table("Students")]
public class Student
{
   [Key]
   public int Id { get; set; }
   public string Name { get; set; }
   public int RollNo { get; set; }
   public string Section { get; set; }
   public string BirthDate { get; set; }
   public string BloodGroup { get; set; }
}
  • You must mark your entity classes with [Table] annotation, otherwise "DbManager", will not be able to include them to the DbContext.

Step 4: Inject DbManager into Your Classes

Inject the AppDbContext class into your desired Controller, Business, or Repository class. For example, in a StudentRepository class:

public class StudentRepository : BaseRepository<Student>, IStudentRepository
{
   public StudentRepository(AppDbContext context) : base(context) // Injected DbManager -> AppDbContext to StudentRepository
   {
   }
}

-----------------------------------------------------------------------------

public interface IStudentRepository : IRepository<Student>
 {
 }
  • In above code, BaseRepository is from "DbManager" library, and IStudentRepository must inherit from "IRepository" of "DbManager" library.

Utilize Pre-defined CRUD Operations

With DbManager integrated into your project, you can take advantage of all the CRUD methods already defined in the BaseRepository class. Here is a quick overview:

  • FindAsync : Find a single entity based on a provided predicate.
  • FetchListBySPAsync: Fetch a list of entities using a stored procedure and parameters.
  • GetAllAsync: Get all entity objects.
  • GetByIdAsync: Retrieve an entity object based on its ID.
  • InsertAsync: Insert a new entity object into the database.
  • UpdateAsync: Update an existing entity object.
  • DeleteAsync : Delete a single entity object.

Remember, all methods are asynchronous, so ensure you use async/await properly while calling them.

Congratulations! You've successfully configured DbManager for your project!

For more detailed information and usage examples, refer to our documentation.

Note: Make sure to add a project reference to DbManager in your solution to access the BaseRepository class and other utilities. For any queries or issues, please reach out to our support team.

Happy Coding with DbManager!

dbmanager's People

Contributors

ony19161 avatar abhikhalid avatar

Stargazers

Jafrul Sadek Nabil avatar

Watchers

 avatar

dbmanager's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.