Skip to content

Data Providers Overview

quyvu edited this page Oct 13, 2026 · 2 revisions

Data Providers Overview

FxMap data providers enable seamless integration with different database technologies, allowing you to fetch and map data efficiently.

What are Data Providers?

Data providers are FxMap extensions that connect your FluentAPI-based entity configs and profiles to actual database systems. They handle query generation, execution, and result mapping automatically.

How They Work

  • Profile Analysis: FxMap analyzes your ProfileOf configs and expressions to understand what data needs to be fetched

  • Query Generation: The data provider translates expressions into optimized database queries

  • Execution: Queries are executed against the database with proper optimization and batching

  • Mapping: Results are automatically mapped to your DTO properties using compiled expressions

Available Data Providers

Entity Framework Core

For SQL databases including SQL Server, PostgreSQL, MySQL, and SQLite. Translates FxMap expressions to optimized SQL queries with proper JOINs.

SQL query optimization

Automatic JOIN generation

Change tracking support

MongoDB

For NoSQL document databases. Leverages MongoDB's aggregation pipeline to efficiently fetch and transform data based on your expressions.

Aggregation pipelines

Document projection

Collection lookups

Basic Configuration

Configuring a data provider is straightforward - add it to your FxMap setup in Program.cs:

Entity Framework Core

builder.Services.AddFxMap(cfg =>
{
    cfg.AddEntitiesFromAssemblyContaining<SomeEntityAssemblyMarker>();
    cfg.AddProfilesFromAssemblyContaining<SomeProfileAssemblyMarker>();
})
.AddEntityFrameworkCore(options => options.AddDbContexts(typeof(AppDbContext)));

MongoDB

builder.Services.AddFxMap(cfg =>
{
    cfg.AddEntitiesFromAssemblyContaining<SomeEntityAssemblyMarker>();
    cfg.AddProfilesFromAssemblyContaining<SomeProfileAssemblyMarker>();
})
.AddMongoDb(cfg => cfg.AddCollection(userCollection).AddCollection(orderCollection));

Performance Characteristics

Query Optimization

Both providers generate optimized queries. EF Core produces efficient SQL with proper indexes and JOINs. MongoDB leverages aggregation pipelines with $lookup and $unwind for optimal document retrieval.

Batching & Caching

FxMap automatically batches multiple related queries and caches results within a request scope, minimizing database round-trips and improving performance.

Compiled Expressions

All FxMap expressions are compiled to optimized code at startup, not using slow reflection at runtime. This results in 10x faster performance compared to traditional mapping approaches.

Choosing a Data Provider

Scenario Recommended Provider
Relational data with complex joins Entity Framework Core
Document-oriented data MongoDB
Existing EF Core application Entity Framework Core
Schema-less flexible data MongoDB
Transaction support required Entity Framework Core

Source: https://fxmapper.net/docs/data-providers/ — the website is always the most up to date version.

Clone this wiki locally