3
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 know basically three ways:
first form:
var resultado = from p in db.Pessoa
where p.DataNasc > x
select new { Id = p.PessoaId, Nome = p.Nome };
second 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, together with the name of each form, an answer that address what is the most appropriate way to obtain a large volume of data taking into account the memory usage RAM, processing and the query sent to the bank (because sometimes the Entity builds querys a lot complex for simple instructions that end up consuming more database server processing).
What is, for you, a large volume of data?
– Intruso
More than 5000 records for me is enough, rsrsrs... :)
– Jedaias Rodrigues
What will you do with this data listing? is a listing screen? is a processing routine? What is the need? For each problem there is a more specific solution. It doesn’t make much sense to simply list by listing, if not for a report.
– Intruso