2
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 Previous:
-- =============================================
-- 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
By the examples I can call the EF consuming the Procedure and I can do lambda, my doubt, in a scenario that I need only quick consultation the two are the same thing? If yes what would be the gain of having a pre-compiled precedent?
I’m using Dapper and put the same SELECT of the project and I saw that much faster than using the EF for consultations. Even in the course I did with Eduardo Pires he recommends the use of Dapper for queries and DELETE INSERT UPDATE use 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 doubt is using Procedure with EF is even thing to do EF with lambda? Is there any gain?
Another use of Dapper simulating Procedure content has some gain?
I think I set the example and I just want to contribute to community, because I know that there are many people who defend only one and the other, but when we know better to use everyone in each situation everyone wins.