How do I ensure that linked objects are loaded using LinqKit?

I am using LinqKit to add "Expression Predicates", I have to do "foreach" to load related objects and it is very expensive for an application to load 1000 records takes 4 minutes on average. Is there a way to speed up this Load process?

public override IQueryable<Entity.Modelos.FluxoDeCaixa> Filtro(System.Linq.Expressions.Expression<System.Func<Entity.Modelos.FluxoDeCaixa, bool>> expressao)
{

    var query = from f in _contexto.FluxoDeCaixa.AsExpandable().Where(expressao)                        
                from fu in _contexto.Funcionario.Where(x => x.PessoaId == f.FuncionarioId)
                from pl in _contexto.PlanoDeContas.Where(x => x.PlanoDeContasId == f.PlanoDeContasId)
                from pf in _contexto.PessoaFisica.Where(x => x.PessoaId == f.PessoaId).DefaultIfEmpty()
                from pj in _contexto.PessoaJuridica.Where(x => x.PessoaId == f.PessoaId).DefaultIfEmpty()                                                
                select f;

    foreach (var f in query)
    {
        _contexto.Entry(f)
        .Reference(r => r.PlanoDeContas)
        .Load();

        _contexto.Entry(f)
            .Reference(r => r.Funcionario)
            .Load();

        _contexto.Entry(f)
            .Reference(r => r.Pessoa)
            .Load();
    }


    return query;
}

      

+3
c # linq entity-framework-4 code-first


source to share


No one has answered this question yet

Check out similar questions:

3575
How to list a transfer?
2058
How do I get a consistent byte representation of strings in C # without manually specifying the encoding?
1877
What is a NullReferenceException and how do I fix it?
1758
How do I generate a random int?
1743
What's the best way to give a C # auto property an initial value?
1742
How to calculate a person's age in C #?
1424
How to fix "The breakpoint will not be removed at this time. No symbols have been loaded for this document." warning?
758
Entity Framework 5 Record Update
756
Failed to check for one or more objects. For more information, see "EntityValidationErrors Property".
0
Using LinqKit to Apply Query to a Single Complex Property



All Articles
Loading...
X
Show
Funny
Dev
Pics