Skip to content

AutoMapper

reference
1 min readUpdated

Kind: Service

Source: Pams/Data/Pams.Data/Pams.Data.csproj (line 1)

Part of: Pams

NuGet package dependency

AutoMapper is a NuGet package dependency declared by Pams.Data. It maps values between .NET object types when the surrounding application configures mapping profiles, keeping data-layer models separate from transferred models.

Diagram

mermaid
flowchart TD
    Source[Data model] --> Profile[AutoMapper mapping profile]
    Profile --> Target[DTO or view model]
    Target --> Consumer[Application consumer]

Usage

typescript
type CustomerDto = {
  customerId: string;
  displayName: string;
};

async function loadCustomer(customerId: string): Promise<CustomerDto> {
  const response = await fetch(`/api/customers/${customerId}`);

  if (!response.ok) {
    throw new Error("Unable to load customer");
  }

  // The API returns a DTO mapped by AutoMapper on the .NET side.
  return response.json();
}

AI Coding Instructions

  • Keep AutoMapper configuration in .NET mapping profiles rather than placing mapping logic in JavaScript clients.
  • Map data-layer entities to DTOs before returning data from application or API boundaries.
  • Do not expose persistence entities directly when a DTO is expected.
  • Update mapping profiles when source or target model properties change.
  • Treat this package as a dependency of Pams.Data; configure mappings in the consuming application code.

Was this page helpful?

Download as PDF