Token导航 LogoToken导航

Agent Skill · 开发

dotnet-data-access-strategy(dotnet 数据访问策略)

用于辅助数据整理、表格处理、CSV/Excel 分析、指标计算和图表准备。它适合让 Agent 清洗字段、汇总数据、发现异常、生成统计口径或把分析结果转成可读说明。使用时需要确认数据来源、字段含义和时间范围,避免把样本数据当全量事实;涉及敏感数据、导出文件或批量写回时,应先确认权限和脱敏边界。

dotnet-data-access-strategy 是开发类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在开发类的 21,746 个 Skill 里排第 18,134。

总安装 356周安装 15GitHub Stars 16下载 125核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dotnet-data-access-strategy(dotnet 数据访问策略)
来源仓库:https://github.com/wshaddix/dotnet-skills
仓库路径:skills/dotnet-data-access-strategy
安装命令:
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-data-access-strategy
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-data-access-strategy

这个 Skill 是做什么的

开发类 Skill 面向写代码、改代码和排查问题,一般会读写仓库文件,部分还会执行构建或测试命令。

该技能提供数据访问技术的决策框架,比较 EF Core、Dapper 和 ADO.NET 优劣。适用于架构选型阶段的 .NET 应用数据层设计决策支持。核心能力包括性能权衡分析、AOT 兼容性和混合方案实施策略。使用时应先明确读写分离需求和聚合边界划分原则。安装前需确认项目目标平台和对启动性能的敏感度要求。

来源仓库内路径:skills/dotnet-data-access-strategy

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-data-acc…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

dotnet-data-access-strategy 怎么安装?

在终端执行 npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-data-access-strate…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

dotnet-data-access-strategy 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

dotnet-data-access-strategy 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

dotnet-data-access-strategy 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

dotnet-data-access-strategy 用的人多吗?

公开数据是累计安装 356 次,近一周安装 15 次,下载 125 次,GitHub 16 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

dotnet-data-access-strategy 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
skill-vetter

技能审查员 · OpenClaw

8,779,018986操作浏览器MIT-0通过
ontology

本体论 · OpenClaw

6,636,960576只读MIT-0通过
entra-app-registration

内部应用程序注册 · Codex、Claude

6,631,872764接触敏感数据未明确通过
entra-app-registration

内部应用程序注册 · Codex、Claude

3,757,680201接触敏感数据未明确通过
nano-banana-pro

纳米香蕉专业版 · OpenClaw

3,526,898364接触敏感数据MIT-0有提醒
dotnet-data-access-strategy

dotnet 数据访问策略 · 本页

35616需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

dotnet-data-access-strategy

Decision framework for choosing between Entity Framework Core, Dapper, and raw ADO.NET in.NET applications. Covers performance tradeoffs, feature comparisons, AOT/trimming compatibility, hybrid approaches, and migration paths. Use this skill to make an informed technology decision before writing data access code.

Out of scope: Tactical EF Core usage (DbContext lifecycle, migrations, interceptors) is covered in [skill:dotnet-efcore-patterns]. Strategic EF Core architecture (read/write split, aggregate boundaries, repository policy) is covered in [skill:dotnet-efcore-architecture]. DI container mechanics -- see [skill:dotnet-csharp-dependency-injection]. Async patterns -- see [skill:dotnet-csharp-async-patterns]. Testing data access layers -- see [skill:dotnet-integration-testing] for database fixture and Testcontainers patterns. CI/CD pipelines -- see [skill:dotnet-gha-patterns] and [skill:dotnet-ado-patterns].

Cross-references: [skill:dotnet-efcore-patterns] for tactical EF Core usage, [skill:dotnet-efcore-architecture] for strategic EF Core patterns, [skill:dotnet-csharp-dependency-injection] for service registration, [skill:dotnet-csharp-async-patterns] for async query patterns.


Decision Matrix

FactorEF CoreDapperRaw ADO.NET
Learning curveModerate (LINQ, migrations, config)Low (SQL + mapping)Low-moderate (SQL + manual mapping)
ProductivityHigh (change tracking, migrations, scaffolding)Moderate (write SQL, auto-map)Low (everything manual)
Query performanceGood with projections; overhead from trackingNear-ADO.NET performanceFastest possible
Startup timeHigher (model building, compilation)MinimalMinimal
Memory allocationHigher (change tracker, proxy objects)Low (direct mapping)Lowest
AOT/trimmingLimited (reflection-heavy, improving)Good with source generatorsFull support
Change trackingBuilt-inNoneNone
MigrationsBuilt-inNone (use FluentMigrator, DbUp, etc.)None
LINQ supportFull (translated to SQL)None (raw SQL)None (raw SQL)
Batch operationsExecuteUpdate/ExecuteDelete (EF Core 7+)Manual batchingManual batching
Complex mappingsExcellent (owned types, TPH/TPT/TPC)Simple POCO mappingManual

When to Choose Each

Choose EF Core When

  • Building CRUD applications with standard domain models
  • You need change tracking and automatic dirty detection
  • You want schema migrations managed in code
  • Your team prefers LINQ over raw SQL
  • You are building with.NET Aspire (EF Core has first-class Aspire integration)
  • Query performance is acceptable with projections and AsNoTracking()
// EF Core: expressive, type-safe, with change tracking
var order = await db.Orders
    .Include(o => o.Items)
    .FirstOrDefaultAsync(o => o.Id == orderId, ct);

order!.Status = OrderStatus.Shipped;
await db.SaveChangesAsync(ct); // Automatic dirty detection

Choose Dapper When

  • Performance is critical and you need control over SQL
  • You are writing complex queries (reporting, analytics, multi-join)
  • You need thin data access with minimal abstraction
  • Your team is comfortable writing and maintaining SQL
  • You need AOT compatibility today (with Dapper.AOT source generator)
// Dapper: direct SQL, minimal overhead
await using var connection = new NpgsqlConnection(connectionString);

var orders = await connection.QueryAsync<OrderDto>(
    """
    SELECT o.id, o.customer_id, o.status, o.created_at,
           COUNT(i.id) AS item_count,
           SUM(i.quantity * i.unit_price) AS total
    FROM orders o
    LEFT JOIN order_items i ON i.order_id = o.id
    WHERE o.customer_id = @CustomerId
    GROUP BY o.id, o.customer_id, o.status, o.created_at
    ORDER BY o.created_at DESC
    LIMIT @PageSize
    """,
    new { CustomerId = customerId, PageSize = pageSize });

Choose Raw ADO.NET When

  • Maximum performance is non-negotiable (sub-millisecond data access)
  • You need full control over connection, command, and reader lifecycle
  • You are building a library or framework (no app-level dependencies)
  • AOT compatibility is required and no source generators are acceptable
  • You are working with stored procedures or database-specific features
// Raw ADO.NET: full control, zero abstraction overhead
await using var connection = new NpgsqlConnection(connectionString);
await connection.OpenAsync(ct);

await using var command = connection.CreateCommand();
command.CommandText = "SELECT id, name, price FROM products WHERE category_id = $1";
command.Parameters.AddWithValue(categoryId);

await using var reader = await command.ExecuteReaderAsync(ct);
var products = new List<ProductDto>();

while (await reader.ReadAsync(ct))
{
    products.Add(new ProductDto
    {
        Id = reader.GetInt32(0),
        Name = reader.GetString(1),
        Price = reader.GetDecimal(2)
    });
}

Performance Comparison

Approximate overhead per query (relative to raw ADO.NET baseline):

OperationADO.NETDapperEF Core (NoTracking)EF Core (Tracking)
Simple SELECT by PK1x~1.05x~1.3x~1.5x
SELECT 100 rows1x~1.1x~1.4x~2x
INSERT single row1x~1.1x~1.5x~2x
Complex JOIN query1x~1.05x~1.3-2x (depends on LINQ translation)~1.5-2.5x

Notes:

  • These are rough relative comparisons -- actual numbers depend on query complexity, database, network latency, and hardware.
  • Network latency to the database typically dwarfs ORM overhead. A 1ms query with 5ms network latency is 6ms regardless of ORM.
  • EF Core with Select() projections and AsNoTracking() approaches Dapper performance for most queries.
  • Measure your actual workload before choosing based on performance alone.

AOT and Trimming Compatibility

EF Core

EF Core relies heavily on reflection for model building, change tracking, and query translation. AOT compatibility is improving but not complete:

FeatureAOT Status (.NET 9+)
Model buildingPartial -- requires compiled model (dotnet ef dbcontext optimize)
Query translationNot AOT-safe (expression tree compilation)
Change trackingNot AOT-safe (proxy generation, snapshot creation)
MigrationsDesign-time only -- not needed at runtime

Compiled models pre-generate the model configuration at build time, reducing startup cost and improving trim-friendliness:

dotnet ef dbcontext optimize \
    --project src/MyApp.Infrastructure \
    --startup-project src/MyApp.Api \
    --output-dir CompiledModels
options.UseNpgsql(connectionString)
       .UseModel(AppDbContextModel.Instance);  // Pre-compiled model

Bottom line: EF Core Native AOT support is partial and version-dependent. As of.NET 9, compiled models improve startup and trim-friendliness, but query translation and change tracking still rely on runtime code generation. Check the current limitations for your target version before committing to EF Core in an AOT deployment. Use compiled models to improve startup time where possible, but plan for Dapper.AOT or ADO.NET fallbacks on AOT-critical paths.

Dapper

Dapper traditionally uses runtime reflection and emit for POCO mapping. The Dapper.AOT source generator provides a trim- and AOT-compatible alternative:

PackageAOT Status
Dapper (standard)Not AOT-safe (uses Reflection.Emit)
Dapper.AOTAOT-safe (source-generated mappers)
<PackageReference Include="Dapper" Version="2.*" />
<PackageReference Include="Dapper.AOT" Version="1.*" />
// Dapper.AOT generates the mapping code at compile time
// Usage is the same as standard Dapper -- the source generator intercepts calls

[DapperAot]  // Attribute enables AOT generation for this class
public sealed class OrderRepository(NpgsqlDataSource dataSource)
{
    public async Task<OrderDto?> GetByIdAsync(int id, CancellationToken ct)
    {
        await using var connection = await dataSource.OpenConnectionAsync(ct);
        return await connection.QuerySingleOrDefaultAsync<OrderDto>(
            "SELECT id, customer_id, status FROM orders WHERE id = @Id",
            new { Id = id });
    }
}

Raw ADO.NET

Full AOT and trimming support. No reflection, no code generation -- all mapping is explicit.

AOT Decision Guide

RequirementRecommendation
Must publish AOT todayDapper.AOT or raw ADO.NET
Prefer ORM, AOT not requiredEF Core
Prefer ORM, AOT planned for futureEF Core now, evaluate AOT support as it improves
Building a library consumed by AOT appsRaw ADO.NET or Dapper.AOT

Hybrid Approaches

Most production applications benefit from using multiple data access technologies. EF Core and Dapper can coexist in the same project, sharing the same database connection.

EF Core for Commands, Dapper for Queries

// Command: use EF Core for change tracking and validation
public sealed class CreateOrderHandler(WriteDbContext db)
{
    public async Task<int> HandleAsync(CreateOrderCommand command, CancellationToken ct)
    {
        var order = new Order(command.CustomerId);
        // ... business logic ...
        db.Orders.Add(order);
        await db.SaveChangesAsync(ct);
        return order.Id;
    }
}

// Query: use Dapper for complex read-only queries
public sealed class OrderReportHandler(NpgsqlDataSource dataSource)
{
    public async Task<IReadOnlyList<OrderReportRow>> HandleAsync(
        OrderReportQuery query,
        CancellationToken ct)
    {
        await using var connection = await dataSource.OpenConnectionAsync(ct);
        var rows = await connection.QueryAsync<OrderReportRow>(
            """
            SELECT
                date_trunc('day', o.created_at) AS day,
                COUNT(*) AS order_count,
                SUM(i.quantity * i.unit_price) AS revenue
            FROM orders o
            JOIN order_items i ON i.order_id = o.id
            WHERE o.created_at >= @StartDate AND o.created_at < @EndDate
            GROUP BY date_trunc('day', o.created_at)
            ORDER BY day
            """,
            new { query.StartDate, query.EndDate });
        return rows.AsList();
    }
}

Sharing the Database Connection

Use DbContext.Database.GetDbConnection() to get the underlying DbConnection for Dapper queries within an EF Core transaction:

public async Task ProcessWithBothAsync(int orderId, CancellationToken ct)
{
    var connection = db.Database.GetDbConnection();
    await db.Database.OpenConnectionAsync(ct);

    await using var transaction = await db.Database.BeginTransactionAsync(ct);

    // EF Core operation
    var order = await db.Orders.FindAsync([orderId], ct);
    order!.Status = OrderStatus.Processing;
    await db.SaveChangesAsync(ct);

    // Dapper operation on the same connection and transaction
    await connection.ExecuteAsync(
        """
        INSERT INTO audit_log (entity_type, entity_id, action, timestamp)
        VALUES (@Type, @Id, @Action, @Timestamp)
        """,
        new { Type = "Order", Id = orderId, Action = "StatusChange",
              Timestamp = DateTimeOffset.UtcNow },
        transaction: transaction.GetDbTransaction());

    await transaction.CommitAsync(ct);
}

NpgsqlDataSource Registration

When using Dapper with PostgreSQL, register NpgsqlDataSource as a singleton in DI (it manages connection pooling internally):

builder.Services.AddNpgsqlDataSource(
    builder.Configuration.GetConnectionString("DefaultConnection")!);

The Npgsql.DependencyInjection package provides AddNpgsqlDataSource(). This also integrates with EF Core -- UseNpgsql() can accept the registered data source:

builder.Services.AddDbContext<AppDbContext>((sp, options) =>
    options.UseNpgsql(sp.GetRequiredService<NpgsqlDataSource>()));

Migration Paths

From Raw ADO.NET to Dapper

Dapper wraps IDbConnection extension methods around existing ADO.NET code. Migration is incremental:

  1. Replace DbDataReader loops with QueryAsync<T>() calls.
  2. Replace command.Parameters.AddWithValue() with anonymous objects.
  3. No schema changes, no new dependencies beyond the Dapper NuGet package.

From Dapper to EF Core

  1. Add EF Core packages and create a DbContext with entity configurations.
  2. Generate initial migration from existing database: dotnet ef dbcontext scaffold.
  3. Gradually replace Dapper queries with EF Core in new features.
  4. Keep Dapper for complex reporting queries -- hybrid is fine.

From EF Core to Dapper/ADO.NET (Performance-Critical Paths)

  1. Identify hot paths via profiling (OpenTelemetry traces, database query stats).
  2. Replace specific queries with Dapper, sharing the same connection.
  3. Keep EF Core for CRUD operations that benefit from change tracking.

Package Reference

PackagePurposeNuGet
Microsoft.EntityFrameworkCoreCore EF frameworkMicrosoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.DesignCLI tooling (migrations, scaffolding)Design-time only
Npgsql.EntityFrameworkCore.PostgreSQLPostgreSQL EF Core providerNpgsql.EntityFrameworkCore.PostgreSQL
Microsoft.EntityFrameworkCore.SqlServerSQL Server EF Core providerMicrosoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.SqliteSQLite EF Core providerMicrosoft.EntityFrameworkCore.Sqlite
DapperMicro-ORMDapper
Dapper.AOTAOT-compatible source generator for DapperDapper.AOT
Npgsql.DependencyInjectionNpgsqlDataSource DI registrationNpgsql.DependencyInjection
NpgsqlPostgreSQL ADO.NET providerNpgsql
Microsoft.Data.SqlClientSQL Server ADO.NET providerMicrosoft.Data.SqlClient
FluentMigratorCode-based migrations (non-EF)FluentMigrator
DbUpSQL script-based migrations (non-EF)dbup

Key Principles

  • Choose based on your actual needs -- not on performance benchmarks. Network latency to the database dwarfs ORM overhead for most applications.
  • EF Core is the default choice for.NET applications -- it provides productivity, safety, and migrations. Optimize with Dapper when profiling identifies specific bottlenecks.
  • Hybrid is the pragmatic answer -- use EF Core for commands and Dapper for complex queries. They share connections and transactions.
  • AOT compatibility matters if you need it -- if publishing AOT is a hard requirement today, use Dapper.AOT or raw ADO.NET. EF Core AOT support is improving but incomplete.
  • Do not prematurely optimize -- start with EF Core, use AsNoTracking() and Select() projections, and measure before introducing Dapper.
  • Migrations are a real productivity feature -- if you choose Dapper, plan your migration strategy separately (FluentMigrator, DbUp, or manual scripts).

Agent Gotchas

  1. Do not recommend Dapper purely for performance without first checking whether EF Core with AsNoTracking() and Select() projections meets the performance requirement. The difference is often negligible when EF Core is used correctly.
  2. Do not use standard Dapper in AOT-published applications -- it uses Reflection.Emit which is not AOT-compatible. Use Dapper.AOT with the [DapperAot] attribute for AOT scenarios.
  3. Do not forget to list required NuGet packages -- both EF Core providers (e.g., Npgsql.EntityFrameworkCore.PostgreSQL) and Dapper packages must be explicitly referenced. Agents that generate code without package references produce non-compiling projects.
  4. Do not create new NpgsqlConnection instances manually in DI-registered services -- use NpgsqlDataSource (registered via AddNpgsqlDataSource()) which manages connection pooling. Creating connections manually bypasses pool management.
  5. Do not mix EF Core and Dapper on separate connections within the same logical transaction -- use DbContext.Database.GetDbConnection() to share the connection and transaction.GetDbTransaction() to share the transaction.
  6. Do not assume EF Core LINQ translates all C# expressions to SQL -- unsupported expressions silently evaluate client-side in older versions or throw in newer versions. Check the generated SQL with ToQueryString() during development.

References

平台分布

Codex

37.08%
按下载量换算46

Claude

27.02%
按下载量换算34

Cursor

17.16%
按下载量换算21

Gemini CLI

9.62%
按下载量换算12

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills