0
I developed a Code First system in Asp.Net MVC In this development I created a relationship far too and I want to do a research that includes this relationships in a survey, below I describe better in code what I developed
I have the following classes. Enterprise, Categories and the relationship class Business.
Business Class
public class Empresa
{
public int Id { get; set; }
public string Nome { get; set; }
public string Telefone { get; set; }
public ICollection<EmpresaCategoria> CategoriaEmpresa { get; set; }
}
Class Category
public class Categoria
{
public int Id { get; set; }
public string Nome { get; set; }
public ICollection<EmpresaCategoria> CategoriaEmpresa { get; set; }
}
Relationship Class Nxn
public class EmpresaCategoria
{
[Key]
public int Id { get; set; }
[ForeignKey("Categoria")]
public int CategoriaId { get; set; }
[ForeignKey("Empresa")]
public int EmpresaId { get; set; }
public virtual Categoria Categoria { get; set; }
public virtual Empresa Empresa { get; set; }
}
In Controller I have a search that works, but it only searches Company, I also want to include the Category
public ActionResult Resultado(string pesquisaEmpresaOuCategoria)
{
if (string.IsNullOrEmpty(pesquisaEmpresaOuCategoria))
{
return Redirect("Index");
}
/*
*Quero Incluir a categoria nesta pesquisa
*include
*/
return View(db.Empresa.Where(x => x.Nome.Contains(pesquisaEmpresaOuCategoria)).ToList());
}
Randrade your answer worked, I would like you to answer me again, because I added new debts on this topic.
– Cyberlacs
@cyberlacs As you have another question, the ideal is to open a new question with your new question. This way we keep track and can help more people. You can link this to the new one to be easier to understand. Taking advantage, if you really open a new question, explain a little more what you want, because I could not understand your editing properly. Any questions just let us know.
– Randrade
taking into account his statement I asked another question this link https://answall.com
– Cyberlacs