MoCrud.Dapper 1.1.66

dotnet add package MoCrud.Dapper --version 1.1.66
                    
NuGet\Install-Package MoCrud.Dapper -Version 1.1.66
                    
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="MoCrud.Dapper" Version="1.1.66" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MoCrud.Dapper" Version="1.1.66" />
                    
Directory.Packages.props
<PackageReference Include="MoCrud.Dapper" />
                    
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 MoCrud.Dapper --version 1.1.66
                    
#r "nuget: MoCrud.Dapper, 1.1.66"
                    
#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 MoCrud.Dapper@1.1.66
                    
#: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=MoCrud.Dapper&version=1.1.66
                    
Install as a Cake Addin
#tool nuget:?package=MoCrud.Dapper&version=1.1.66
                    
Install as a Cake Tool

Dapper.MoCrud

A simple CRUD helper extension built on top of Dapper.
Auto-generates Get, GetList, Insert, Update, Delete queries from POCO classes and attributes, minimizing repetitive SQL.

Features

  • Auto SQL generation ? Select / Insert / Update / Delete from POCO classes
  • Sync & Async ? Every CRUD method has an Async counterpart
  • Multi-DB support ? SQL Server, SQL Server 2012+, PostgreSQL, SQLite, MySQL, Oracle, DB2
  • Paging ? Server-side paging via GetListPaged
  • Partial update ? Update only specific properties
  • Composite keys ? Composite Primary Key support
  • Custom Resolver ? Swap table/column name strategies with ITableNameResolver, IColumnNameResolver
  • ILogger integration ? Query tracing via Microsoft.Extensions.Logging
  • net8.0 / netstandard2.0 multi-target

Install

dotnet add package MoCrud.Dapper

Quick Start

1. Define Entity

using Dapper.MoCrud.Attributes;

[Table("Users")]
public class User
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }

    [IgnoreInsert]
    [ReadOnly(true)]
    public DateTime CreatedDate { get; set; }
}

2. Set Dialect (default: SQL Server)

CrudHelper.SetDialect(CrudHelper.Dialect.SQLite);

3. CRUD Usage

using Dapper.MoCrud;

// Get by Id
var user = connection.Get<User>(1);

// Get by conditions
var user = connection.Get<User>("where Name = @Name", new { Name = "Alice" });

// GetList ? anonymous object conditions
var users = connection.GetList<User>(new { Age = 30 });

// GetList ? SQL where clause
var users = connection.GetList<User>("where Age > @Age", new { Age = 20 });

// GetAll
var allUsers = connection.GetAll<User>();

// GetListPaged (pageNumber, rowsPerPage, conditions, orderBy)
var paged = connection.GetListPaged<User>(1, 10, "where Age > 20", "Name");

// Insert ? returns new Id
int? newId = connection.Insert(new User { Name = "Bob", Age = 25 });

// Insert ? specify return type
long newId = connection.Insert<long, User>(new User { Name = "Bob", Age = 25 });

// Update ? all properties
connection.Update(user);

// Update ? specific properties only
connection.Update(user, new[] { "Name", "Age" });

// Delete ? by entity
connection.Delete(user);

// Delete ? by Id
connection.Delete<User>(1);

// DeleteList ? anonymous object conditions
connection.DeleteList<User>(new { Age = 30 });

// DeleteList ? SQL where clause
connection.DeleteList<User>("where Age < @Age", new { Age = 18 });

// RecordCount
int count = connection.RecordCount<User>("where Age > @Age", new { Age = 20 });

4. Async Support

Every method has an Async version.

var user  = await connection.GetAsync<User>(1);
var users = await connection.GetListAsync<User>(new { Age = 30 });
int? id   = await connection.InsertAsync(new User { Name = "Eve", Age = 28 });
await connection.UpdateAsync(user);
await connection.DeleteAsync(user);
int count = await connection.RecordCountAsync<User>();

Attributes

Attribute Target Description
[Table("name", Schema = "schema")] Class Table name and schema
[Column("name")] Property Column name mapping
[Key] Property Auto-increment (identity) Primary Key
[ExplicitKey] Property Manually assigned Primary Key
[Required] Property Required property (included in Insert even if Key)
[Editable(false)] Property Excluded from Insert / Update
[ReadOnly(true)] Property Excluded from Update
[NotMapped] Property Excluded from all SQL
[IgnoreSelect] Property Excluded from Select
[IgnoreInsert] Property Excluded from Insert
[IgnoreUpdate] Property Excluded from Update

Supported Dialects

CrudHelper.SetDialect(CrudHelper.Dialect.SQLServer);      // default
CrudHelper.SetDialect(CrudHelper.Dialect.SQLServer2012);   // OFFSET-FETCH paging
CrudHelper.SetDialect(CrudHelper.Dialect.PostgreSQL);
CrudHelper.SetDialect(CrudHelper.Dialect.SQLite);
CrudHelper.SetDialect(CrudHelper.Dialect.MySQL);
CrudHelper.SetDialect(CrudHelper.Dialect.Oracle);
CrudHelper.SetDialect(CrudHelper.Dialect.DB2);

Custom Resolver

public class SnakeCaseTableNameResolver : CrudHelper.ITableNameResolver
{
    public string ResolveTableName(Type type)
    {
        return CrudHelper.Encapsulate(ToSnakeCase(type.Name));
    }
}

CrudHelper.SetTableNameResolver(new SnakeCaseTableNameResolver());
CrudHelper.SetColumnNameResolver(new MyColumnNameResolver());

Logging

CrudHelper.SetLogger(loggerFactory.CreateLogger("Dapper.MoCrud"));

Generated SQL is traced at LogTrace level.

License

Apache-2.0 ? See LICENSE

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 is compatible.  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
1.1.66 121 2/25/2026