0

I am using UOW in an ASP.NET Core Web API with EF Core. When trying to read values from a stored procedure with UOW the dbContext.Database.SqlQuery method is not found.

Currently I'm using EF Core 5 and .NET 5.

This is my IRepository interface:

public interface IUnitOfWorkIntegrado
{
    IRepository<T> Repository<T>() where T : class;
    Task SaveChangesAsync();
    Task BeginTransactionAsync();
    Task RollBackAsync();
    Task CommitAsync();
    Task<List<T>> GetSP<T>() where T : class;
}

My UOW implementation:

public class UnitOfWorkIntegrado : IUnitOfWorkIntegrado
{
    public Task<List<T>> GetSP<T>() where T : class
    {
        // SqlQuery does not appear as a method   
        return dbContext.Database
                        .SqlQuery<T>(spQuery, parameters).ToList(); 
    }
}

How can I implement this pattern?

Progman
  • 16,827
  • 6
  • 33
  • 48
redredred
  • 1
  • 1
  • .NET uses dependecy injection. You need to inject the dataContext as a service. It has to be registered in Startup.cs as a service as well. – Canolyb1 Jul 13 '21 at 16:35
  • That's right, there is no such method - `SqlQuery`. See the [docs](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.infrastructure.databasefacade?view=efcore-5.0#extension-methods). There are methods `ExecuteSqlRaw`, `ExecuteSqlInterpolated`. – Alexander Petrov Jul 13 '21 at 17:53

0 Answers0