I would like to query 2 different databases (2 Dbcontext)
I have tried in several ways, one of them: I make a pre-query in the context DbMega to recover the officials
var FuncionariosLinq = (from Colaborador in dbMega.Funcionarios
select new Funcionario
{
FuncionarioId = Colaborador.FuncionarioId,
Nome = Colaborador.Nome,
}).ToArray();
and then I query the other context with inner join
with this pre query:
var Linq = (from sal in db.fechamentoSalarios
join Funcionarios in FuncionariosLinq
on sal.FuncionarioId equals Funcionarios.FuncionarioId into output
where sal.Data.Year == DataFiltro.Year && sal.Data.Month == DataFiltro.Month
select new GerenciarSalariosViewModel
{
Data = sal.Data,
FuncionarioNome = output.FirstOrDefault().Nome
SalarioId = sal.SalarioId,
Valor = sal.Valor
}
);
Displays the error:
The entity or complex type 'WMB.Models.Funtionary' can not be constructed in a LINQ to Entities query.
If I change instead of Select new Funcionario
leave select new {
in:
var FuncionariosLinq = (from Colaborador in dbMega.Funcionarios
select new Funcionario
{
FuncionarioId = Colaborador.FuncionarioId,
Nome = Colaborador.Nome,
}).ToArray();
Displays the error:
Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context.
I decided to send the official ID and in the view calling a function that retrieves the user's name, but it was not so perfomous and I think this should be something normal an inner join on different banks, just do not know how to do it. p>