I have a query where I have multiple data return from each user. But when I perform a search, I have the returned data as a return.
I know that this repetition of the data occurs because I do not contain a single data (not repeated) in this query, as a primary key
, since the basis for this query is a View
created in my DataBase
.
I know this, because if I add this line in my query (where I create a Codigo
field with a single count for each row) I can return the data without repeating.
ROW_NUMBER() OVER(ORDER BY Nome desc ) AS 'Codigo'
Problem: When adding the row in my View (SQL) the query does not repeat the data, but a query that takes 4 seconds to accomplish, adding this row to the same query takes 8 minutes.
Is there a way to return this data without repeating the code, or another way to treat my View (SQL)?
My controller that does this query looks like this:
public ActionResult Dependente()
{
var dependente =
dependenteRepository.Dependentes.Where(r => r.CdMatricula == matricula && r.SqContrato == contrato).ToList();
return View(dependente);
}
My model looks like this:
public class Dependente
{
public double NRCPF { get; set; }
public string NmPessoa { get; set; }
public string Nome_dependente { get; set; }
public string DsGrauDependencia { get; set; }
public int CdMatricula { get; set; }
public Int16 SqContrato { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? Nascimento { get; set; }
}