I have a list of Objects with a list of types inside of each Object, somthing very similar like this:
public class ExampleObject
{
public int Id {get; set;}
public IEnumerable <int> Types {get;set;}
}
For example:
var typesAdmited = new List<int> { 13, 11, 67, 226, 82, 1, 66 };
And inside the list of Object I have an object like this:
Object.Id = 288;
Object.Types = new List<int> { 94, 13, 11, 67, 254, 256, 226, 82, 1, 66, 497, 21};
But when I use linq to get all Object who has the types admited I get any results. I am trying this:
var objectsAdmited = objects.Where(b => b.Types.All(t => typesAdmited.Contains(t)));
Example:
var typesAdmited = new List<int> { 13, 11, 67, 226, 82, 1, 66 };
var objectNotAdmited = new ExampleObeject {Id = 1, Types = new List<int> {13,11}};
var objectAdmited = new ExampleObject {Id = 288, Types = new List<int> { 94, 13, 11, 67, 254, 256, 226, 82, 1, 66, 497, 21}};
var allObjects = new List<ExampleObject> { objectNotAdmited, objectAdmited };
var objectsAdmited = allObjects.Where(b => b.Types.All(t => typesAdmited.Contains(t)));
I get:
objectsAdmited = { }
And it should be:
objectsAdmited = { objectAdmited }