ApexSoft.DapperExtensions 1.0.1

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

ApexSoft.DapperExtensions

ApexSoft.DapperExtensions, .NET projelerinizde Dapper ORM kullanırken tekrarlayan CRUD ve Bulk işlemlerini soyutlayan, hafif ve yüksek performanslı bir extension kütüphanesidir. Dapper'ın ham SQL gücünü korurken Entity Framework benzeri bir kullanım konforu sunar.

Özellikler

  1. Sıfır bağımlılık yükü: Yalnızca Dapper ve Microsoft.Data.SqlClient üzerine inşa edilmiştir.
  2. Attribute tabanlı eşleme: [Table], [Key], [DatabaseGenerated], [NotMapped] attribute'ları ile entity-tablo eşlemesi.
  3. Reflection önbellekleme: EntityMapper sınıfı tüm metadata'yı ConcurrentDictionary ile önbellekler; her sorgu için tekrar reflection yapılmaz.
  4. Composite key desteği: Birden fazla [Key] property içeren entity'ler desteklenir.
  5. Bulk işlemler: Dapper batch yürütme ve SqlBulkCopy tabanlı yüksek hacimli insert desteği.
  6. Multi-targeting: .NET 8.0 ve .NET 9.0 ile tam uyumlu.

Kurulum

dotnet add package ApexSoft.DapperExtensions

Entity Tanımı

using ApexSoft_DapperExtensions.Attributes;

// Tablo adı sınıf adından farklıysa [Table] kullanın.
[Table("Users")]
public class User
{
    // [Key] + [DatabaseGenerated] → INSERT ve UPDATE'ten otomatik hariç tutulur.
    [Key]
    [DatabaseGenerated]
    public int Id { get; set; }

    public string Name     { get; set; } = string.Empty;
    public string Email    { get; set; } = string.Empty;
    public bool   IsActive { get; set; }

    // [NotMapped] → hiçbir SQL işlemine dahil edilmez.
    [NotMapped]
    public string FullLabel => $"{Id} - {Name}";
}

Attribute Referansı

Attribute Hedef Açıklama
[Table("name")] Class Veritabanı tablo adını belirtir. Yazılmazsa sınıf adı kullanılır.
[Key] Property Primary key kolonunu işaretler. Yazılmazsa Id isim kuralı uygulanır.
[DatabaseGenerated] Property Kolonu INSERT/UPDATE'ten hariç tutar (IDENTITY kolonlar için).
[NotMapped] Property Kolonu tüm SQL işlemlerinden hariç tutar.

Kullanım

Bağlantı Kurulumu

using Microsoft.Data.SqlClient;

await using var conn = new SqlConnection("Server=.;Database=MyDb;Trusted_Connection=True;");
await conn.OpenAsync();

CRUD — Tekil İşlemler

Insert
var user = new User { Name = "Ahmet Yılmaz", Email = "ahmet@ornek.com", IsActive = true };

// Oluşturulan Id değerini döner. Identity yoksa 0 döner.
int newId = await conn.InsertAsync(user);
Select
// Id ile tek kayıt
User? user = await conn.GetAsync<User>(newId);

// Tüm kayıtlar
IEnumerable<User> all = await conn.GetAllAsync<User>();

// Sayfalama ile
IEnumerable<User> page = await conn.GetAllAsync<User>(QueryOptions.Page(pageNumber: 1, pageSize: 20));

// Dinamik filtre ile — null olmayan property'ler WHERE koşuluna eklenir
IEnumerable<User> filtered = await conn.GetAllByFilterAsync<User>(
    new { IsActive = true, Name = "Ahmet" },
    QueryOptions.Page(1, 50));
Update
user.Name = "Ahmet Can Yılmaz";
bool updated = await conn.UpdateAsync(user);
Delete
// Entity üzerinden
bool deleted = await conn.DeleteAsync(user);

// Sadece Id ile
bool deletedById = await conn.DeleteByIdAsync<User>(42);

Transaction Kullanımı

await using var tx = conn.BeginTransaction();
try
{
    await conn.InsertAsync(new User { Name = "Ali",  Email = "ali@ornek.com",  IsActive = true }, tx);
    await conn.InsertAsync(new User { Name = "Veli", Email = "veli@ornek.com", IsActive = true }, tx);
    tx.Commit();
}
catch
{
    tx.Rollback();
    throw;
}

Tüm CRUD ve Bulk metodları IDbTransaction parametresi kabul eder.


Bulk İşlemler

Bulk metodlar, özellikle toplu veri yükleme senaryolarında tekil CRUD işlemlerine göre çok daha verimlidir.

Bulk Insert / Update / Delete
var users = Enumerable.Range(1, 100)
    .Select(i => new User { Name = $"Kullanıcı {i}", Email = $"k{i}@ornek.com", IsActive = true })
    .ToList();

int inserted = await conn.BulkInsertAsync(users);
int updated  = await conn.BulkUpdateAsync(users);
int deleted  = await conn.BulkDeleteAsync(users);

// Id listesi ile toplu silme
int deletedByIds = await conn.BulkDeleteByIdsAsync<User>(new[] { 1, 2, 3 });
SqlBulkCopy — Yüksek Hacimli Insert

Binlerce satır eklenecekse BulkCopyAsync tercih edilmelidir. Yalnızca SqlConnection ile çalışır.

// IEnumerable<TEntity> overload — DataTable hazırlamak gerekmez
await BulkCopyHelper.BulkCopyAsync(conn, users);

// Özel DataTable ile
await BulkCopyHelper.BulkCopyAsync(conn, dataTable, destinationTable: "Users");
Yöntem Ne zaman kullanılmalı
BulkInsertAsync Yüzlerce satıra kadar, herhangi bir IDbConnection
BulkCopyAsync Binlerce satır, yalnızca SQL Server

QueryOptions

// Sayfa tabanlı (önerilen)
var opts = QueryOptions.Page(pageNumber: 2, pageSize: 25);

// Manuel
var opts = new QueryOptions
{
    Limit      = 25,
    Offset     = 25,
    OrderBy    = "Name",
    Descending = true
};

Composite Key

[Table("OrderItems")]
public class OrderItem
{
    [Key] public int OrderId   { get; set; }
    [Key] public int ProductId { get; set; }

    public int     Quantity  { get; set; }
    public decimal UnitPrice { get; set; }
}

// WHERE OrderId=@OrderId AND ProductId=@ProductId olarak üretilir
bool deleted = await conn.DeleteAsync(orderItem);
int  updated = await conn.BulkUpdateAsync(orderItems);

Gereksinimler

  • .NET 8.0 veya .NET 9.0
  • Dapper 2.x
  • Microsoft.Data.SqlClient 5.x
  • SQL Server 2012+ (OFFSET/FETCH ve SCOPE_IDENTITY için)

Developer: Seyfullah Tanrıverdi

Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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. 
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.0.1 125 5/15/2026
1.0.0 112 5/15/2026

Initial release — CRUD, Bulk, BulkCopy, composite key, attribute mapping.