I have this sql Query:
SELECT *
FROM [Incentivos].[dbo].[Incentivos] AS I
INNER JOIN [Incentivos].[dbo].[Captura] AS C ON I.CapturaID = C.ID
WHERE I.EmpleadoID =4530 and C.mdEstatusRegistro = 1
It works correctly, now I want to use it with LINQ, so I try
var ce = _contexto.Empleados.Where(x => x.nCodigoEmpleado == codigoEmpleado)
.Select(x => x.ID).FirstOrDefault(); //4530 value
var captura = _contexto.Capturas.Where(x => x.mdEstatusRegistro).ToList(); //Captura table
//JOIN
var Incentivo = _contexto.Incentivos
.Join(captura, x => x.CapturaID, y => y.ID, (x, y) => new { x, y })
.Where(x => x.y.mdEstatusRegistro && x.x.EmpleadoID == ce)
.Select(b=> b.x).FirstOrDefault();
Problem is Join always come null, what am I doing wrong? regards
UPDATE: I change query more simple like
var Incentivo = from incentivos in _contexto.Incentivos
join captura in _contexto.Capturas on incentivos.CapturaID equals captura.ID
where (incentivos.EmpleadoID == ce) && (captura.mdEstatusRegistro == true)
select incentivos;
But now after query I want to access Incentivo like:
Incentivo.nPorcentajeAJU //Property of Incentivo table
But I can't , how can I access variables now?
AND C.mdEstatusRegistro = 1validation in sql just return one value @DavidGFirstOrDefaultonly returns the default value for an empty set, otherwise it returns the first item.contexto.Empleados.Where(emp=>emp.Captura.mdEstatusRegistro && emp.EmpleadoID==4530)