ApexSoft.DapperExtensions
1.0.1
dotnet add package ApexSoft.DapperExtensions --version 1.0.1
NuGet\Install-Package ApexSoft.DapperExtensions -Version 1.0.1
<PackageReference Include="ApexSoft.DapperExtensions" Version="1.0.1" />
<PackageVersion Include="ApexSoft.DapperExtensions" Version="1.0.1" />
<PackageReference Include="ApexSoft.DapperExtensions" />
paket add ApexSoft.DapperExtensions --version 1.0.1
#r "nuget: ApexSoft.DapperExtensions, 1.0.1"
#:package ApexSoft.DapperExtensions@1.0.1
#addin nuget:?package=ApexSoft.DapperExtensions&version=1.0.1
#tool nuget:?package=ApexSoft.DapperExtensions&version=1.0.1
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
- Sıfır bağımlılık yükü: Yalnızca Dapper ve Microsoft.Data.SqlClient üzerine inşa edilmiştir.
- Attribute tabanlı eşleme:
[Table],[Key],[DatabaseGenerated],[NotMapped]attribute'ları ile entity-tablo eşlemesi. - Reflection önbellekleme:
EntityMappersınıfı tüm metadata'yıConcurrentDictionaryile önbellekler; her sorgu için tekrar reflection yapılmaz. - Composite key desteği: Birden fazla
[Key]property içeren entity'ler desteklenir. - Bulk işlemler: Dapper batch yürütme ve
SqlBulkCopytabanlı yüksek hacimli insert desteği. - 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 | Versions 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. |
-
net8.0
- Dapper (>= 2.1.72)
- Dapper.SqlBuilder (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 7.0.1)
-
net9.0
- Dapper (>= 2.1.72)
- Dapper.SqlBuilder (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 7.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release — CRUD, Bulk, BulkCopy, composite key, attribute mapping.