When to use Entity Framework example:
var registros = db.Tabela.AsQueryable();
registros = registros.Where(r =>
(intTipo == 0 || r.IdTipo == intTipo) &&
r.IdArea == intIdArea &&
r.DataInicio <= DateTime.Now &&
(r.DataFim == null || r.DataFim >= DateTime.Now) &&
r.Aprovado == true &&
r.Homologado == true &&
r.Excluido == false);
When to use procedure:
-- =============================================
-- Author: Anderson
-- Create date: 22/01/2015
-- Description: Teste
-- =============================================
CREATE PROCEDURE TestedePerformace
@intTipo int = 0,
@intIdArea int = 0
AS
BEGIN
SELECT * FROM TABELA R
WHERE ( R.INTTIPO = @intTipo OR R.INTTIPO = 0 )
AND r.IdArea == @intIdArea
AND ( r.DataInicio <= DateTime.Now or r.DataInicio = null)
AND r.Aprovado = 1
AND r.homologado = 1
AND r.excluido = 0
END
GO
For examples I can call EF consuming the procedure and I can do lambda, my doubt, in a scenario that I need only quick consultation are the two the same thing? If so, what would be the gain of having a precompiled procedure?
I'm using Dapper and put the same SELECT of the procedure and validated that well faster than using EF for queries. Even in the course I did with Eduardo Pires he recommends using Dapper for queries and DELETE INSERT UPDATE using EF with Lambda .
A table with 800 record
//Begin timing
stopWatch.Start();
var listaEF = autorizacaoRepository.All();
var listaDapper = autorizacaoRepositoryReader.All();
//Stop timing
stopWatch.Stop();
// Write result
//Dapper TotalSeconds = 0.0016825
//EF TotalSeconds = 3.928575
//var time = stopWatch.Elapsed;
My question is the use of Procedure with EF is same thing as doing EF with lambda? Is there any gain?
Does the use of Dapper simulating the content of the Procedure have any gain?
I think I've set the example and I just want to contribute to the community, because I know there are many people who defend only one and the other, but when we know how to use everyone in every situation, everyone wins.