Skip to content
Back to skills

Coreex Repository

ASecurity

Create or modify a CoreEx Infrastructure-layer repository. USE FOR: new repository class, adding CRUD operations, adding a custom query (QueryArgsConfig<TSelf>), bidirectional mapper (BiDirectionMapper), EfDb/CosmosDb model accessor, Result<T> pipeline variants. DO NOT USE FOR: Application-layer service logic, domain invariants, typed HTTP clients/adapters (those follow adapter conventions in the infrastructure instructions, not this skill).

  • 29 stars
  • 0 votes
  • 0 copies
  • 8 views
  • Added August 31, 2026
databasessqlgitdatabase

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 9, 2026

npx -y skills add Avanade/CoreEx --skill coreex-repository --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Coreex Repository?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Coreex Repository
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/avanade-coreex-repository/badge)](https://www.skillsdirectory.com/skills/avanade-coreex-repository)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: coreex-repository
description: "Create or modify a CoreEx Infrastructure-layer repository. USE FOR: new repository class, adding CRUD operations, adding a custom query (QueryArgsConfig<TSelf>), bidirectional mapper (BiDirectionMapper), EfDb/CosmosDb model accessor, Result<T> pipeline variants. DO NOT USE FOR: Application-layer service logic, domain invariants, typed HTTP clients/adapters (those follow adapter conventions in the infrastructure instructions, not this skill)."
argument-hint: "Optional: entity name, database type (PostgreSQL/SQL Server/Cosmos), operations needed (get/create/update/delete/query), new or existing repository; for query: filtering (default: yes), ordering (default: yes), paging (default: yes), count support (default: no), then per filter field: name + property type + allowed operators + case-insensitive? + model mapping if different"
tags: ["repository", "infrastructure", "efcore", "mapping", "coreex", "data-access", "result"]
---

<!--
  AI workflow asset — dual-audience notice:
  - In the Avanade/CoreEx repository: this file is the authored source. Edit it here.
  - In a consumer repository: this file was generated by `dotnet new coreex-ai` (or refreshed via
    `dotnet new coreex-ai --force` / the `/coreex-docs-sync` skill). Do not hand-edit it directly —
    propose the change upstream in Avanade/CoreEx instead, then refresh once it is released.
-->

# CoreEx: Repository

Guides you through creating or modifying a CoreEx Infrastructure-layer repository in `Infrastructure/Repositories/`. Covers CRUD delegates, custom queries, bidirectional mappers, EfDb or CosmosDb accessors, and `Result<T>` pipelines.

## When to Use

- New repository class for an entity (scaffold, EfDb/CosmosDb accessor, mapper, registration)
- Adding a CRUD operation (get/create/update/delete) using EfDb delegate shortcuts
- Adding a custom query method with `QueryArgsConfig` dynamic filtering/ordering
- Adding a `BiDirectionMapper` (Contract ↔ Persistence) in `Infrastructure/Mapping/`
- Adding or modifying an `EfDbMappedModel` / `EfDbModel` accessor on `*EfDb`, or a `CosmosDbContainer<TModel>` / `CosmosDbMappedContainer<...>` accessor on `*CosmosDb`
- Switching a method to the `Result<T>` / `*WithResultAsync` pipeline

## When Not to Use

- Application-layer service logic — inject the repository interface, do not modify it from Infrastructure
- Domain aggregates, entities, value objects — those belong in the Domain layer
- Persistence model class creation — those are generated by the `*.Database` tooling; run `dotnet run -- CodeGen` there

## Quick Reference

**Resolve context before coding; ask only about unresolved behavior:**
- Take the entity and operations from the request; inspect the existing repository, provider, Domain layer, and ROP style against Feature Configuration.
- For queries, reuse supplied field/operator/sort requirements and existing configuration. Inspect contracts and mappings for types and model names; ask only about unresolved exposure, matching, or default ordering. Entity shape alone does not authorize exposing a field.

**Key rules at a glance:**
- `[ScopedService<IInterface>]` on every repository class — auto-registers in DI
- Primary constructor: relational example `public class ProductRepository(ProductsEfDb ef) : IProductRepository`; Cosmos example `public class CustomerRepository(CustomersCosmosDb cosmos) : ICustomerRepository`; always guard the injected accessor with `ThrowIfNull()`
- Use the provider's typed accessors: `EfDb` delegate shortcuts (`GetAsync`, `CreateAsync`, `UpdateAsync`, `DeleteAsync`) for relational domains; `CosmosDbMappedContainer` / `CosmosDbContainer` delegates for Cosmos domains. Never write raw `DbContext` CRUD or instantiate a `CosmosClient` in the repository.
- Create/Update return `DataResult<T>` or `Result<DataResult<T>>`; Delete returns `DataResult` or `Result<DataResult>`. Use `dr.Map(value => SomeMapper.Map(value))` to preserve `WasMutated` through ROP/Domain mapping until Application gates mutation events; prefer the lambda to retain CoreEx mapper nullability guarantees. Do not implicitly unwrap or default the flag to true. Aggregate outcomes cover the whole parent/child operation; reads remain unchanged.
- `*WithResultAsync` variants for `Result<T>` ROP pipelines (per-project style choice)
- `BiDirectionMapper`: override **both** `OnMap` overloads; map `Id` explicitly; **never** map `ETag` or `ChangeLog` — base mapper owns them
- `QueryArgsConfig<TSelf>`: create a dedicated `{Name}QueryArgsConfig : QueryArgsConfig<{Name}QueryArgsConfig>` class per entity in `Infrastructure/Repositories/`; access via `.Default`; call `.Parse(query).ThrowOnError()` before use — never instantiate per-request. Relational queries materialize from `IQueryable<TModel>` extensions; Cosmos queries materialize from `CosmosDbQuery<TModel>` instance methods (`Container.Query(...).ToMappedItemsResultAsync(...)`).
- Custom relational SQL: prefer `EfDb` for ordinary CRUD/LINQ; put application-owned static SQL (short or long) in embedded `.sql` / `.pgsql` resources loaded by `SqlStatement.FromResource<TResource>`, and bind values with `.Param(...)`. Reserve `FromText(...)` for SQL genuinely generated at runtime, with dynamic identifiers validated or safely quoted; schema changes belong in DbEx migrations.
- `AddReferenceDataField<TRef>(field, model, ...)`: `field` is always the contract's generated nav property (`{Name}`, never `{Name}Code`) — a fixed, documented source-generator convention, **not** something to verify by exploring generated code
- `ToMappedItemsResultAsync(mapper, paging, cancellationToken: cancellationToken)`: always pass `cancellationToken` **by name** — `autoCount` (`bool`, defaults `true`) sits before it in the signature, and a bare positional token there fails to compile
- Always `.ConfigureAwait(false)` on every `await`
- In mappings, pass stored codes directly to concrete reference-data parameters/properties (`Currency = source.CurrencyCode`); do not add `RefData<T>` helpers or conversion-only lookups. See [conversion semantics](/.github/instructions/coreex-contracts.instructions.md#reference-data-code-conversion).

For full workflow and code examples see [`references/workflow.md`](references/workflow.md).

## Key References

- [`/.github/instructions/coreex-repositories.instructions.md`](/.github/instructions/coreex-repositories.instructions.md) — full conventions: EfDb, DbContext, mappers, query config, adapters
- [CoreEx.Database guide](/.github/docs/coreex/agents/CoreEx.Database.md) — direct relational SQL with `IDatabase`, `SqlStatement`, and embedded resources
- Related skills: [`coreex-db-migration`](../coreex-db-migration/SKILL.md) (generates the persistence models this maps), [`coreex-app-service`](../coreex-app-service/SKILL.md) + [`coreex-adapter`](../coreex-adapter/SKILL.md) (consumers), [`coreex-aggregate`](../coreex-aggregate/SKILL.md) (persisting aggregates)
- Illustrative examples (CoreEx sample — not present in your project):
  - [contract-mapping repositories](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Products.Infrastructure/Repositories) — `ProductRepository` (CRUD + query), `ProductsEfDb`, `ProductsDbContext` — and [BiDirectionMapper](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Products.Infrastructure/Mapping) (`ProductMapper`)
  - [Custom SQL with embedded resources](https://github.com/Avanade/CoreEx/blob/main/samples/src/Contoso.Products.Infrastructure/Repositories/ProductSearchIndex.cs) — `SqlStatement.FromResource`, bound parameters, and `ProductsEfDb.Database`
  - [Domain-mapping repositories](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Infrastructure/Repositories) — `BasketRepository` (`Result<T>` + Domain mapping) — and [one-way Domain ↔ Persistence mappers](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Infrastructure/Mapping) (`BasketMapper`)

Files in this skill

  • SKILL.md6.4 KB
  • references/workflow.md21.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.