Lambda with different contexts

Asked

Viewed 183 times

7

Is there any way to join two or more tables using Lambda and two different contexts?

1 answer

5


Can use Linq To Objects, that is, manipulating data in memory, recommended also AsNoTrancking() not to cache the queries.

Example

IList<Pessoa> Pessoas = null;
using (Dba1 dba1 = new Dba1())
{
    Pessoas = dba1.Pessoa.AsNoTracking().ToList();
}


IList<Telefone> Telefones = null;
using (Dba2 dba2 = new Dba2())
{
    Telefones = dba2.Telefone.AsNoTracking().ToList();
}


Pessoas.Join(Telefones, x => x.Id, g => g.PessoaId, (x, g) => new { x, g })
       .Select(s => new
       {
           s.g.Ddd, 
           s.g.Numero, 
           s.g.PessoaId,
           s.x.Nome
       }).ToList();

Obs: It is not very performatic, but in specific cases can be well used, can not become rule of its application.

References:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.