GenericCRUDHelper 2.0.0

dotnet add package GenericCRUDHelper --version 2.0.0
                    
NuGet\Install-Package GenericCRUDHelper -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GenericCRUDHelper" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GenericCRUDHelper" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GenericCRUDHelper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GenericCRUDHelper --version 2.0.0
                    
#r "nuget: GenericCRUDHelper, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GenericCRUDHelper@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GenericCRUDHelper&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GenericCRUDHelper&version=2.0.0
                    
Install as a Cake Tool

GenericCRUDHelper

GenericCRUDHelper is a lightweight and flexible .NET Standard 2.0 library that enables seamless CRUD operations across multiple databases. Designed for simplicity and extensibility, it abstracts the complexities of database-specific code and allows consistent interaction through a clean, connection string–driven approach.


πŸ“‘ Table of Contents

  • Installation
  • Documentation
  • Usage
  • Supported Databases
  • Features
  • Compatibility
  • Configuration Requirement
  • Driver Recommendation for AS400
  • Limitations
  • Disclaimer
  • Contact

πŸ“₯ Installation

Install via NuGet:

.NET CLI

   dotnet add package GenericCRUDHelper

Package Manager

   Install-Package GenericCRUDHelper

πŸ“˜ Documentation

To help you configure and use the GenericCrudHelper in your project, a detailed PDF guide is included within the NuGet package.

πŸš€ 1. Automatic Integration (Recommended)

To automatically access the setup PDF:

βœ… Step-by-Step:

  1. Clear your local NuGet cache (to ensure no stale packages are used):

       dotnet nuget locals all --clear
    
  2. Install the GenericCrudHelper package

       dotnet add package GenericCrudHelper
    
  3. Clean and then build your solution or project:

       dotnet clean
       dotnet build
    
  4. After a successful build, check your solution/project directory. You should now see a new folder:

       <YourProjectRoot>/Docs/GeneriCRUDHelperDocument.pdf
    

    If the file does not appear automatically, follow the Manual Access steps below.

πŸ› οΈ 2. Manual Access

If the automatic method fails or you want to extract the file manually:

βœ… Step-by-Step:

  1. Navigate to the NuGet cache folder:

       %USERPROFILE%\.nuget\packages\genericcrudhelper\<version>\
    
  2. Copy the .nupkg file to another location:

  3. Rename the file from .nupkg to .zip, then extract it.

  4. Open the extracted folder and navigate to:

       contentFiles/any/any/Docs/GeneriCRUDHelperDocument.pdf
    

You can now open or copy the PDF guide into your project manually.

⚠️ Note on Restoring the PDF Document

If you manually delete the Docs folder or the GeneriCRUDHelperDocument.pdf file from your project after installing the GenericCRUDHelper NuGet package:

Visual Studio will add a <Content Remove="..."/> entry in your .csproj file to exclude the file from future builds.

  1. To restore the document:

    Open your .csproj file Remove the block similar to:

    <ItemGroup>
      <Content Remove="C:\Users\YourName\.nuget\packages\genericcrudhelper\...\GeneriCRUDHelperDocument.pdf" />
    </ItemGroup>
    
  2. Clean the solution (Build > Clean Solution)

  3. Rebuild the solution (Build > Build Solution)

This will allow the NuGet package to re-inject the PDF file into your project and copy it to the appropriate output directory.


πŸš€ Usage

Basic example:

    using GenericCRUDHelper;

    public class ClassName 
    {
        // Create an Instance of IRepositoryGeneric 
        private readonly IRepositoryGeneric _repositoryGeneric;

        public ClassName(IRepositoryGeneric repositoryGeneric)
        {
            _repositoryGeneric = repositoryGeneric;
        }
        public void MethodName {

        // List of data
        var results = _repositoryGeneric.GetAll<Entity>();
    
        // fetch a record by Id
        var result = _repositoryGeneric.Get<ModelClass>(1);
    
        // insert method
        var insertData = _repositoryGeneric.Insert<ModelClass>(new Entity { Type="State", Description="Rajasthan"});
    
        //update method
        result.Description = "Delhi";
        var updateData = _repositoryGeneric.Update<ModelClass>(Entityresult);
    
        // delete method
        var deleteData = _repositoryGeneric.Delete<ModelClass>(1);
        }
    }

πŸ—„οΈ Supported Databases

  • βœ… Microsoft SQL Server
  • βœ… MySQL
  • βœ… PostgreSQL
  • βœ… SQLite
  • βœ… AS400

✨ Features

  • πŸ”Œ Connect to multiple databases using simple connection strings
  • ⚑ Generic CRUD operations with minimal boilerplate
  • 🧱 Built on .NET Standard 2.0 for broad compatibility
  • πŸ“¦ Lightweight with no heavy ORM dependencies
  • πŸ”„ Support for both sync and async operations (if applicable)
  • πŸ“ Optional logging support via ILogger (can be skipped; uses NullLogger by default)
  • 🧠 Optional in-memory caching via ICacheProvider (can be skipped; repository works without it)
  • πŸ› οΈ Support for executing built-in and user-defined database functions, including stored procedures
  • πŸ”’ Transaction support for bulk operations such as bulk insert and bulk update
  • πŸ” LINQ-inspired fluent API for expressive, chainable queries

βš™οΈ Compatibility

Cross-Language Support

  • βœ… C#
  • βœ… VB.NET

Architecture Support

  • βœ… ASP.NET Web API
  • βœ… ASP.NET MVC
  • βœ… ASP.NET Web Forms
  • βœ… ASP.NET Core (MVC & Web API)

Framework Support:

GenericCRUDHelper is compatible with any .NET platform that supports .NET Standard 2.0.

Supported Frameworks:

  • βœ… .NET Standard 2.0
  • βœ… .NET Core 3.1
  • βœ… .NET Framework 4.8
  • βœ… .NET 6 / .NET 7 / .NET 8 / .NET 9

Configuration Requirement

Common Requirement

  1. Install GenericCrudHelper NugetPackage

  2. Configuration: Depending on your target platform, use the appropriate configuration method below:

πŸ”· For .NET Core 6 and Above

Add the following configuration to your appsettings.json file:

   "DatabaseType": "SqlServer",
   //"DatabaseType": "MySql",
   //"DatabaseType": "PgSql",
   //"DatabaseType": "SQLite",
   //"DatabaseType": "AS400",
   "ConnectionStrings": {
   "DefaultConnectionString": "Server=ServerName;Database=DatabaseName;Trusted_Connection=True;"
   //"DefaultConnectionString": "Server=ServerName;Database=DatabaseName;User=root;Password=MySQLPassword;"
   //"DefaultConnectionString": "Host=ServerName;Database=DatabaseName;Username=postgres;Password=PostgresSQLPassword;"
   //"DefaultConnectionString": "Data Source=Path\\DatabaseName.sqlite;"
   //"DefaultConnectionString": "Driver={IBM i Access ODBC Driver};System=ServerIP;Uid=Userid;Pwd=Password;SSL=true;",
   },

🟦 For .NET Framework 4.8 (ASP.NET MVC / VB.NET)

Add the configuration in your Web.config file:

   <configuration>
      <appSettings>
         <add key="DatabaseType" value="SqlServer" />
         // <add key="DatabaseType" value="MySql" />
         // <add key="DatabaseType" value="PgSql" /> 
         // <add key="DatabaseType" value="SQLite" /> 
         // <add key="DatabaseType" value="AS400" /> 
      </appSettings>

      <connectionStrings>
         // SQL Server 
         <add name="DefaultConnectionString" 
         connectionString="Server=ServerName;Database=DatabaseName;Trusted_Connection=True;" 
         providerName="System.Data.SqlClient" />

         // MySQL
         // <add name="DefaultConnectionString" 
         // connectionString="Server=ServerName; Database=DatabaseName; User=root; Password=MySQLPassword;"
         // providerName="MySql.Data.MySqlClient" /> 

         // PostgreSQL 
         // <add name="DefaultConnectionString" 
         // connectionString="Host=ServerName; Database=DatabaseName; Username=postgres; Password=PostgresSQLPassword;"
         // providerName="Npgsql" /> 

         // SQLite 
         // <add name="DefaultConnectionString" 
         // connectionString="Data Source=Path\\DatabaseName.sqlite;" 
         // providerName="System.Data.SQLite" /> 

         // AS400 (via ODBC) 
         // <add name="DefaultConnectionString" 
         // connectionString="Driver={IBM i Access ODBC Driver};System=ServerIP;Uid=Userid;Pwd=Password;SSL=true
         // providerName="System.Data.Odbc" /> 
      </connectionStrings>
   </configuration>

Framework specific Requirement

πŸ”· For .NET Core 6 and Above

  1. Add connection string and DBType entries in appsettings.json file

  2. In Program.cs file inject object via Dependency Injection.

    builder.Services.AddTransient<IRepositoryGeneric>(sp =>
   {
      var configuration = sp.GetRequiredService<IConfiguration>();
      var connectionString = configuration.GetConnectionString("DefaultConnectionString");

      var dbTypeString = configuration.GetValue<string>("DatabaseType");
      if (!Enum.TryParse<DatabaseType>(dbTypeString, out var dbType))
         throw new InvalidOperationException($"Invalid DatabaseType: {dbTypeString}");

      var connectionFactory = new DbConnectionFactoryProvider(connectionString);

      // Register repository without logger and cache
      return new GenericCRUDHelper.Repository(connectionFactory, dbType);

      // -----------------------------------
      // Optional: Register with logger and cache
      // -----------------------------------
      // var logger = sp.GetRequiredService<ILogger<GenericCRUDHelper.Repository>>();
      // var memoryCache = new MemoryCache(new MemoryCacheOptions());
      // var cacheProvider = new MemoryCacheProvider(memoryCache);
      // return new GenericCRUDHelper.Repository(connectionFactory, dbType, logger, cacheProvider);
   });

🟦 For .NET Framework 4.8 (VB.Net compatibility of Nuget package.)

  1. Unity Container Package need to install

  2. Add connection string and DBType entries in web.config file

  3. In Global.asax inject object via Dependency Injection

      Dim container As New UnityContainer()
      Dim connectionString As String = ConfigurationManager.ConnectionStrings("PgDefaultConnectionString").ConnectionString
      Dim dbType As DatabaseType = CType([Enum].Parse(GetType(DatabaseType), "DatabaseType"), DatabaseType)
      Dim connectionFactoryProvider As IDbConnectionFactoryProvider = New DbConnectionFactoryProvider(connectionString)

      ' Register repository without logger and cache
      container.RegisterFactory(Of IRepositoryGeneric)(
         Function(c) New GenericCRUDHelper.Repository(connectionFactoryProvider, dbType)
      )

      ' -------------------------
      ' Optional: Register with logger and cache
      ' -------------------------
      ' Dim logger As ILogger(Of GenericCRUDHelper.Repository) = NullLogger(Of GenericCRUDHelper.Repository).Instance
      ' Dim memoryCache = New MemoryCache(New MemoryCacheOptions())
      ' Dim cacheProvider As ICacheProvider = New MemoryCacheProvider(memoryCache)
      ' container.RegisterFactory(Of IRepositoryGeneric)(
      '     Function(c) New GenericCRUDHelper.Repository(connectionFactoryProvider, dbType, logger, cacheProvider)
      ' )

      DependencyResolver.SetResolver(New UnityDependencyResolver(container))

🟦 For .NET Framework 4.8 (C# compatibility of Nuget package.)

  1. Unity Container Package need to install

  2. Add connection string and DBType entries in web.config file

  3. In App_Start, Go to Unity.Config.cs file insert below code on RegisterComponent method

      var container = new UnityContainer();
      container.RegisterFactory<IRepositoryGeneric>(c =>
      {
         var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString;
         var dbTypeString = System.Configuration.ConfigurationManager.AppSettings["DatabaseType"];
         var dbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), dbTypeString);
         var connectionFactoryProvider = new DbConnectionFactoryProvider(connectionString);

         // Return repository without logger and cache
         return new GenericCRUDHelper.Repository(connectionFactoryProvider, dbType);

         // -----------------------------------
         // Optional: Register with logger and cache
         // -----------------------------------
         // var logger = Microsoft.Extensions.Logging.Abstractions.NullLogger<GenericCRUDHelper.Repository>.Instance;
         // var memoryCacheOptions = new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions();
         // var memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(memoryCacheOptions);
         // var cacheProvider = new GenericCRUDHelper.Cache.MemoryCacheProvider(memoryCache);
         // return new GenericCRUDHelper.Repository(connectionFactoryProvider, dbType, logger, cacheProvider);
      });
      DependencyResolver.SetResolver(new UnityDependencyResolver(container));

For detailed guidline please refer pdf file: "GenericCrudHelper.pdf" which is embaded with GenericCrudHelper NugetPackage.


πŸ’Ύ Driver Recommendation for AS400

To integrate with AS400 systems, it is recommended to use the official IBM i Access Client Solutions (ACS) ODBC Driver for optimal compatibility and performance.

Recommended Drivers

  • IBM i Access Client Solutions (ACS) ODBC Driver – 64-bit
    Provides reliable ODBC connectivity to AS400 databases.

Installation

  1. Download and install the IBM i Access Client Solutions package from the official IBM website:
    IBM i Access Client Solutions

  2. Ensure the drivers are properly configured on your machine.

Sample Connection String

Here is a sample connection string for the IBM i Access .NET provider:

   string connectionString = "Driver={IBM i Access ODBC Driver}; System=Your_System_Name; Uid=Your_UID_; Pwd=Your_Password;DefaultLibraries=Your_Library; SSL=true;";

Limitations

1. Data Type Limitations

  • DateOnly and TimeOnly types are not supported in this project.
  • Use DateTime instead for any date or time-related data.
  • Ensure time components are zeroed out if you only intend to store a date (e.g., 2025-04-22T00:00:00).
  • If you only need time, consider using a TimeSpan or a string in HH:mm:ss format.

❓ Why?

Compatibility reasons: The project targets a .NET version or framework where DateOnly/TimeOnly is not available or not yet integrated.


πŸ“’ Disclaimer

By using the GenericCRUDHelper NuGet package, you acknowledge and agree to the following:

1. No Warranty: This package is provided "as is", without any warranties of any kind, express or implied. The authors and publishers disclaim all warranties, including but not limited to merchantability, fitness for a particular purpose, and non-infringement.

2. Usage at Your Own Risk: You assume full responsibility for any consequences resulting from the use of this package, including but not limited to data loss, corruption, application errors, or failures.

3. Data Security: You are solely responsible for securing your data and ensuring compliance with all applicable data protection laws and regulations.

4. Third-Party Dependencies: This package may include or rely on third-party libraries. The authors and publishers are not responsible for any issues, including bugs or vulnerabilities, arising from such dependencies.

5. Compliance: You are responsible for ensuring that your use of this package complies with all relevant laws, regulations, and licensing requirements.

6. No Redistribution: You may not redistribute, reverse engineer, decompile, or modify this package, in whole or in part, without prior written permission from the publisher.


πŸ“« Contact

Maintained by Programmers.io

Have questions, issues, or feedback? Feel free to open an issue or reach out to us directly.


Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 149 1/29/2026
1.0.3 384 6/11/2025
1.0.2 502 4/24/2025
1.0.1 193 1/29/2025
1.0.0 196 1/17/2025

## New Features and Enhancements

- Optional logging support via ILogger
Fully optional; defaults to NullLogger when not provided.

- Optional in-memory caching via ICacheProvider
Repository functions correctly even when caching is disabled.

- Execution support for built-in and user-defined database routines
Includes PostgreSQL functions and stored procedures.

- Transaction support for bulk operations
Covers bulk insert and bulk update scenarios.

- LINQ-inspired fluent API
Enables expressive, readable, and chainable query construction.

- Dynamic stored procedure execution (ExecuteSPList, ExecuteSPListAsync)
Introduced a fully dynamic execution model to remove previous PostgreSQL execution constraints.


## PostgreSQL Stored Procedure Support (Fully Resolved)

Stored procedure execution now provides complete support for all PostgreSQL return patterns, including combined usage of refcursor and OUT parameters.

## Supported Scenarios

- Stored procedures with no result set
- Stored procedures with OUT parameters only
- Mapped to a dictionary of output values
- Stored procedures returning a refcursor
- Fetches and returns a list of records
- Stored procedures returning both refcursor and OUT parameters
- Returns the refcursor result set
- Also returns all OUT parameter values correctly

## PostgreSQL Notes

- The refcursor parameter must be the last parameter in the stored procedure and must be named ref.
Example: INOUT ref refcursor

- OUT or INOUT parameters (e.g., row_count) must appear before the refcursor.
Include these in the outputParameterNames list.

- The outputParameterNames and returnsRefCursor parameters in ExecuteSPList or ExecuteSPListAsync are only required for PostgreSQL procedures.

## Improvement

- Previously, PostgreSQL procedures that returned both a refcursor and OUT parameters could only return the cursor results.
- This limitation has now been fully eliminated through a dynamic execution and mapping strategy, without requiring composite types or wrapper functions.