can anyone help me. I'm trying to get results from my query but can't get them to work. i'm making query in connection table whitch connects other 3 tables.. and for a result i need to get Radnja.Grad,Radnja.Naziv_radnje,Modeli.Naziv_modela,Dijelovi.Naziv and Dijelovi.Cijena from tables.. here is my tables and connections and code that i got stuck on.
public async Task<IActionResult> trazi(string grad, string model, string dio)
{
var query = from veza in db.ModeliRadnjas
join dijelovi in db.Dijelovis on veza.IdDijela equals dijelovi.IdDijela
join radnja in db.Radnjas on veza.IdRadnje equals radnja.IdRadnje
join auto in db.Modelis on veza.IdModela equals auto.IdModela
select veza;
if (!String.IsNullOrEmpty(grad) && !String.IsNullOrEmpty(model) && !String.IsNullOrEmpty(dio))
{
query = query.Where(veza => veza.IdRadnjeNavigation.Grad.Equals(grad) && veza.IdModelaNavigation.NazivModela.Equals(model) && veza.IdDijelaNavigation.Naziv.Equals(dio));
}
else if (!String.IsNullOrEmpty(model) && !String.IsNullOrEmpty(dio))
{
query = query.Where(veza => veza.IdModelaNavigation.NazivModela.Equals(model) && veza.IdDijelaNavigation.Naziv.Equals(dio));
}
else if (!String.IsNullOrEmpty(grad) && !String.IsNullOrEmpty(model))
{
query = query.Where(veza => veza.IdRadnjeNavigation.Grad.Equals(grad) && veza.IdModelaNavigation.NazivModela.Equals(model));
}
else if (!String.IsNullOrEmpty(grad))
{
query = query.Where(veza => veza.IdRadnjeNavigation.Grad.Equals(grad));
}
else if (!String.IsNullOrEmpty(model))
{
query = query.Where(veza => veza.IdModelaNavigation.NazivModela.Equals(model));
}
else if (!String.IsNullOrEmpty(dio))
{
query = query.Where(veza => veza.IdDijelaNavigation.Naziv.Equals(dio));
}
else
{
}
return View(await query.ToListAsync());
If you want to retrieve the database in this way, you need to add the three fields of IdRadnjeNavigation, IdModelaNavigation, IdDijelaNavigation to the ModeliRadnjas table, and you need to gradually retrieve the matching fields.
Below is my test code,it works fine:
Modeli_Radnja.cs:
Controller:
Test Result:
Then you can take the value you want from it.