GenericCRUDHelper 2.0.0
dotnet add package GenericCRUDHelper --version 2.0.0
NuGet\Install-Package GenericCRUDHelper -Version 2.0.0
<PackageReference Include="GenericCRUDHelper" Version="2.0.0" />
<PackageVersion Include="GenericCRUDHelper" Version="2.0.0" />
<PackageReference Include="GenericCRUDHelper" />
paket add GenericCRUDHelper --version 2.0.0
#r "nuget: GenericCRUDHelper, 2.0.0"
#:package GenericCRUDHelper@2.0.0
#addin nuget:?package=GenericCRUDHelper&version=2.0.0
#tool nuget:?package=GenericCRUDHelper&version=2.0.0
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:
Clear your local NuGet cache (to ensure no stale packages are used):
dotnet nuget locals all --clearInstall the GenericCrudHelper package
dotnet add package GenericCrudHelperClean and then build your solution or project:
dotnet clean dotnet buildAfter a successful build, check your solution/project directory. You should now see a new folder:
<YourProjectRoot>/Docs/GeneriCRUDHelperDocument.pdfIf 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:
Navigate to the NuGet cache folder:
%USERPROFILE%\.nuget\packages\genericcrudhelper\<version>\Copy the .nupkg file to another location:
Rename the file from .nupkg to .zip, then extract it.
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.
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>Clean the solution (Build > Clean Solution)
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
Install GenericCrudHelper NugetPackage
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
Add connection string and DBType entries in appsettings.json file
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.)
Unity Container Package need to install
Add connection string and DBType entries in web.config file
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.)
Unity Container Package need to install
Add connection string and DBType entries in web.config file
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
Download and install the IBM i Access Client Solutions package from the official IBM website:
IBM i Access Client SolutionsEnsure 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 | Versions 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. |
-
.NETStandard 2.0
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Data.Sqlite (>= 9.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- MySql.Data (>= 9.1.0)
- Npgsql (>= 8.0.3)
- System.Data.Odbc (>= 6.0.0)
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
## 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.