I’m currently developing a site using Code First and Linq to entities.
I Have a custom model called Productos that contains a list of custom models called Especificaciones, wich also contains a custom model called Etiquetas. Etiquetas has a Property Called EtiquetaId.
This is an example of my models:
public class ObjectProducto
{
public IEnumerable<ObjectEspecificaciones> Especificaciones { get; set; }
}
public class ObjectEspecificaciones
{
public IEnumerable<Etiquetas> etiquetas { get; set; }
}
public class Etiquetas
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EtiquetaId { get; set; }
public string texto { get; set; }
}
I Have an int array filled with values from a view, the array is called MyOptions.
I need to get all the Especificaciones that contains all Etiquetas with EtiquetaId inside MyOptions.
At this point i have retrieved all the Especificaciones that match with ANY of the values inside MyOptions, but i need the Etiquetas Inside Especificaciones that match by ALL MyOptions values.
I have the values from Productos, with all their Especificaciones and all of the Etiquetas inside all of Especificaciones already inside a var called procatm.
Currently my query looks like this:
ProductosCatalogo =
(from procatm in catm.ProductosCatalogo
where procatm.Especificaciones.Any(e => e.etiquetas.Any(et =>
et.tipo_etiqueta.CompareTo("categoria") != 0 &&
et.tipo_etiqueta.CompareTo("tipo") != 0 &&
MyOptions.Contains(et.EtiquetaId)))
select procatm).AsEnumerable()
I don’t know if i can make something like
ProductosCatalogo =
(from procatm in catm.ProductosCatalogo
where procatm.Especificaciones.Any(e => e.etiquetas.Any(et =>
et.tipo_etiqueta.CompareTo("categoria") != 0 &&
et.tipo_etiqueta.CompareTo("tipo") != 0 &&
MyOptions.All(...).....
select procatm).AsEnumerable()
Can somebody helpme?
I believe I din’t explained the question far enough..
Only needed to check if an array of Etiquetas was a subset of another array, but all elements in opciones was contained in the tags Ienumerable.
Found the answer 🙂
Thanks to all the persons that submitted an answer 😀