1
I would like to make a query in 2 different databases (2 Dbcontext)
I tried it in several ways, one of them: I make a prequery in Dbmega context to recover the employees
var FuncionariosLinq = (from Colaborador in dbMega.Funcionarios
select new Funcionario
{
FuncionarioId = Colaborador.FuncionarioId,
Nome = Colaborador.Nome,
}).ToArray();
and then do the consultation in the other context with inner join
with this prior consultation:
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.Funcionario' cannot be constructed in a LINQ to Entities query.
If I change instead of Select new Funcionario
let 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 employee ID and in the view calling a function that retrieves the user name, but it was not so perfomatic and I believe that this should be something normal an Inner Join in different banks, I just do not know how to do.