1
I have a query where I have returned several data of each user. However, when performing a search, I have as return the repeated data.
I know that this repetition of the data happens because I do not contain a single data (that does not repeat) in this query, as a primary key
, as the basis for this consultation is a View
maid in my DataBase
.
I know this because if I add this line in my query (where I create a field Codigo
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 line in my View (SQL) the query does not repeat the data, but a query that takes 4 seconds to perform, when adding this line the same query takes 8 minutes.
There is a way to return this data without repeating by code, or another way to treat my View (SQL)?
My controller that makes this query is like this:
public ActionResult Dependente()
{
var dependente =
dependenteRepository.Dependentes.Where(r => r.CdMatricula == matricula && r.SqContrato == contrato).ToList();
return View(dependente);
}
My model is that way:
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; }
}
"I have a View in my sql". This statement does not make any sense. SQLS do not return Views, but if I understand well what you want to do is enumerate the lines. I do not know what the purpose of this, but I will answer.
– Leonel Sanches da Silva
@In this sentence the idea was to say that return the data of a View( create View nmView as select...) I added the word "SQL" just to distinguish from the View of MVC. Sorry if you got confused, but I can edit for better understanding.
– Randrade
Yes, it would be nice.
– Leonel Sanches da Silva