Using transactions in custom SQL operations

If we are using Entity Framework, we most likely want it to handle database operations for us. However, there may be cases where we need to leverage SQL directly, in order to achieve something that Entity Framework does not support, such as a complex SQL query or running stored procedures. For that, Entity Framework Core lets us use the underlying ADO.NET connection directly. If, however, we plan to make use of transactions created explicitly, we need to tell it to use the created transaction.

Getting ready

We will be using the NuGet Package Manager to install Entity Framework Core 1 package, Microsoft.EntityFrameworkCore. We will also be using a SQL Server database for storing the data, so we will also ...

Get Entity Framework Core Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.