﻿---
title: Set up Entity Framework Core instrumentation
description: How to enable Elastic APM .NET Agent instrumentation of Entity Framework Core database operations to capture them as APM spans.
url: https://www.elastic.co/elastic/docs-builder/docs/3410/reference/apm/agents/dotnet/setup-ef-core
products:
  - APM .NET Agent
  - APM Agent
applies_to:
  - Serverless Observability projects: Generally available
  - Elastic Stack: Generally available
  - Application Performance Monitoring Agent for .NET: Generally available
---

# Set up Entity Framework Core instrumentation
## Supported versions


| Package                         | Supported versions |
|---------------------------------|--------------------|
| `Microsoft.EntityFrameworkCore` | ≥8.0.0 ≤10.0.x     |

For the full compatibility matrix including supported installation methods, refer to [Data access technologies](/elastic/docs-builder/docs/3410/reference/apm/agents/dotnet/supported-technologies#supported-data-access-technologies).

## Quick start

This page assumes the core agent is already set up. If not, see [Set up the APM .NET Agent](https://www.elastic.co/elastic/docs-builder/docs/3410/reference/apm/agents/dotnet/set-up-apm-net-agent) first.
Add the [`Elastic.Apm.EntityFrameworkCore`](https://www.nuget.org/packages/Elastic.Apm.EntityFrameworkCore) NuGet package to your project:
```sh
dotnet add package Elastic.Apm.EntityFrameworkCore
```

Pass `EfCoreDiagnosticsSubscriber` to the `AddElasticApm` method in case of ASP.NET Core, as follows:
```csharp
using Elastic.Apm.EntityFrameworkCore;

app.Services.AddElasticApm(new EfCoreDiagnosticsSubscriber());
```

or passing `EfCoreDiagnosticsSubscriber` to the `Subscribe` method
```csharp
using Elastic.Apm;
using Elastic.Apm.EntityFrameworkCore;

Agent.Subscribe(new EfCoreDiagnosticsSubscriber());
```

Instrumentation listens for diagnostic events raised by `Microsoft.EntityFrameworkCore`, creating database spans for executed commands.