I'm having problems performing a select (using LINQ) in a View in SQL Server 2012. The values stored in the database are as below:
ID_Acomp ID_Pessoa Nome Data
26 300 MONTEIRO 01-01-2016
27 300 MONTEIRO 02-02-2016
28 300 MONTEIRO 03-03-2016
When I perform the select in SQL Manager, the values return perfectly. But when I do the same select through LINQ, the value of the last record is replicated over the other records above, and looks like this:
ID_Acomp ID_Pessoa Nome Data
28 300 MONTEIRO 03-03-2016
28 300 MONTEIRO 03-03-2016
28 300 MONTEIRO 03-03-2016
The code I'm using in the application is basically this:
IQueryable<VW_PESSOA_ACOMPANHAMENTO> vwPessoaAcomp =
contexto.VW_PESSOA_ACOMPANHAMENTO.AsQueryable();
if (ID_Pessoa > 0)
{
vwPessoaAcomp = vwPessoaAcomp(p => p.ID_Pessoa == ID_Pessoa);
}
var retorno = (from A in vwPessoaAcomp
orderby A.ID_Acomp descending
select A).ToList();
Below is the code for my view:
SELECT A.ID_Acomp, P.ID_Pessoa, P.Nome, A.Data
FROM ACOMPANHAMENTO A, PESSOA P WHERE A.ID_ACOMP = P.ID_ACOMP