2
I’m doing a heritage system, where I can register a heritage and link to it a room. In this system I have a tab of reports, where I have a field that I must type the name of a room and a button to filter. When I click on the button I should return all the patrimonies registered with that room, but it returns me all the patrimonies.
I have the Reporiocontroller class with the search method
public IActionResult Busca(string nome)
{
var resultado = _relatorioService.listarPatrimonios(nome);
return View(resultado);
}
And I have the Reportarioservice class with the method
public List<Patrimonio> listarPatrimonios(string local)
{
var resultado = from obj in _context.Patrimonio select obj;
return resultado.Include(obj => obj.Local).Include(obj => obj.Equipamento).OrderBy(obj => obj.Id).ToList();
}
Could someone tell me where the mistake is?
local model
namespace CheckPatWebMVC.Models
{
public class Local
{
public int Id { get; set; }
public string Nome { get; set; }
}
}
heritage model
namespace CheckPatWebMVC.Models
{
public class Patrimonio
{
public int Id { get; set; }
public int NumeroPatrimonio { get; set; }
public string NumeroSerie { get; set; }
public Equipamento Equipamento { get; set; }
public int EquipamentoId { get; set; } //Garantir que o Id deverá existir
public Local Local { get; set; }
public int LocalId { get; set; } //Garantir que o Id deverá existir
public string Coordenadas { get; set; }
public string Usuario { get; set; }
public string Observacao { get; set; }
public bool Manutencao { get; set; }
}
}
Could you share the models of the classes? From what I saw there in your code in no time in the listPatrimonios you end up filtering by site. You can use a LINQ Where to filter in the heritage context
– luturol
Thanks for the indication. Do you mind pointing out what was different from the answer, so I can correct it? Obg.
– tvdias