Given a list of groupos, where each groupo has a single empresa and multiple groupos can have the same empresa, how do you get the empresas that contain any of the list's groupos?
I have this Model:
public class Grupo
{
public int id { get; set; }
public string descripccion { get; set; }
[ForeignKey("Empresas")]
public int empresa { get; set; }
public virtual empresa Empresas { get; set; }
}
public class empresa
{
public int id { get; set; }
public string descripcion { get; set; }
public virtual ICollection<Grupo> Grupos { get; set; }
}
So this method gives me a List
private List<Grupo> VerEmpresas(int userId)
{
var lista = (from ga in db.GrupoAccesos
join g in db.Grupos
on ga.grupo equals g.id
where ga.usuario == userId
select g).ToList();
return lista;
}
and now I want to use this method to show me the empresas that are related to grupo.
Below emp gives a bool, and instead I want all the empresas that are in my list of grupos.
List<Grupo> verEmpresa = VerEmpresas(1);
var emp = (from p in db.Empresas
select p.Grupos).Contains(verEmpresa);
ViewBag.empresa = new SelectList(emp, "id", "descripcion");