How to use the . Sqlquery expression of EF in Efcore?

Asked

Viewed 59 times

0

I’m refactoring a code and I’m having that doubt.

public class MovimentoManualListRepository : RepositoryBase<MovimentoManualList>, IMovimentoManualListRepository
{
    ConsultarContext _context;
    public MovimentoManualListRepository(ConsultarContext context) : base(context)
    {
        _context = context;
    }

    public List<MovimentoManualList> Listar()
    {
        return _context.Database
            .SqlQuery<MovimentoManualList>("ListarMovimentacao")
            .ToList();
    }
}

I end up getting such a mistake:

Error CS1061: 'Databasefacade' does not contain a Definition for 'Sqlquery' and no accessible Extension method 'Sqlquery' Accepting a first argument of type 'Databasefacade' could be found (are you Missing a using Directive or an Assembly Reference?)

1 answer

0


The resolution was to use the . Fromsql method to run the Procedure.

public class MovimentoManualListRepository : RepositoryBase<MovimentoManualList>, IMovimentoManualListRepository
    {
        ConsultarContext _context;
        public MovimentoManualListRepository(ConsultarContext context) : base(context)
        {
            _context = context;
        }

        public List<MovimentoManualList> Listar()
        {
            return _context.MovimentoManualLists
                .FromSql("EXECUTE dbo.ListarMovimentacao")
                .ToList();
        }
    }

In addition to creating a new property in my context

public DbQuery<MovimentoManualList> MovimentoManualLists { get; set; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.