> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/umbraco-ui-builder/17.latest/advanced/efcore-events.md).

# EF Core Events

Umbraco UI Builder now supports EF Core. It publishes specific notifications, allowing you to modify queries before and after they are built.

These are the EF Core equivalents of the NPoco `SqlQueryBuildingNotification` and `SqlQueryBuiltNotification`.

## Registering Event Handlers

Umbraco UI Builder follows the [Umbraco Notification mechanism](https://docs.umbraco.com/umbraco-cms/develop-with-umbraco/application-code/backend-and-custom-logic/subscribing-to-notifications) for event registration.

To define a notification event handler for the target event, please check the [Registering Event Handlers](/umbraco-ui-builder/17.latest/advanced/events.md) section.

### Using the `EFCoreQueryBuildingNotification`

Triggers when the default EF Core repository is **preparing** a query. The notification provides access to the `IQueryable`, where clause, order by expression, collection alias, and entity type. You can modify these to customize the query before execution.

#### Example

```csharp
public class MyEFCoreQueryBuildingHandler : INotificationHandler<EFCoreQueryBuildingNotification>
{
    public void Handle(EFCoreQueryBuildingNotification notification)
    {
        // Access query properties
        var collectionAlias = notification.Args.CollectionAlias;
        var entityType = notification.Args.EntityType;

        // Modify the IQueryable directly
        // notification.Args.Query = ...
    }
}
```

### Using the `EFCoreQueryBuiltNotification`

Triggers when the default EF Core repository has **completed** building a query. The notification contains the final `IQueryable`, where clause, and order by expressions that were used to generate the query.

#### Example

```csharp
public class MyEFCoreQueryBuiltHandler : INotificationHandler<EFCoreQueryBuiltNotification>
{
    public void Handle(EFCoreQueryBuiltNotification notification)
    {
        // Inspect or further modify the built query
        var query = notification.Args.Query;
    }
}
```

### Registering Event Handlers

Register EF Core query event handlers the same way you would other Umbraco notifications:

```csharp
builder.CreateUmbracoBuilder()
    .AddBackOffice()
    .AddWebsite()
    .AddDeliveryApi()
    .AddComposers()
    .AddNotificationHandler<EFCoreQueryBuildingNotification, MyEFCoreQueryBuildingHandler>()
    .AddNotificationHandler<EFCoreQueryBuiltNotification, MyEFCoreQueryBuiltHandler>()
    .Build();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.umbraco.com/umbraco-ui-builder/17.latest/advanced/efcore-events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
