I have a project in Asp.Net MVC where I need to work with a large volume of data. To get them from the Database (Microsoft SQL Server) using Entity Framework 4 I basically know three ways:
1st form:
var resultado = from p in db.Pessoa
where p.DataNasc > x
select new { Id = p.PessoaId, Nome = p.Nome };
2nd form:
var cmd = string.format(@"SELECT p.PessoaId, p.Nome
FROM Pessoa p
WHERE p.DataNasc > {0}", x);
var objectContext = ((IObjectContextAdapter)db).ObjectContext;
var resultado = objectContext.ExecuteStoreQuery<PessoaCustom>(cmd).ToList<PessoaCustom>();
3rd form:
var resultado = db.Pessoa.Where(p => p.DataNasc > x).Select(p => new {Id = p.PessoaId, Nome = p.Nome});
I would like, along with the name of each form, a response that the most appropriate way to achieve a large volume of data taking into account the RAM usage , processing and the query sent to the bank (because sometimes Entity builds querys a lot for simple instructions that end up consuming more processing of the database server).