0

I have an IQueryable of Gizmo.

I want to write LINQ statement that will filter all Gizmos whose color is in the parameter (string[]) that I pass.

For example:

public class Gizmo
{
      public string Id { get; set; }

      public string Name { get; set; }

      public virtual ICollection<Color> Colors { get; set; } = new List<Color>();
}

public class Color
{
      public string Id { get; set; }
      public string Value { get; set; } 
}

I will be supplied a parameter like:

var filterColors = new[] { "red", "silver" };

I want to write something similar to:

gizmos = gizmos.Where(x => x.ColorTags.Contains(filterColors));
1
  • 1
    Okay, so you wrote it, what happened? Commented Dec 5, 2018 at 18:18

1 Answer 1

2

Seems like you're looking for:

gizmos = gizmos.Where(x => filterColors.Any(z => x.Colors.Any(e => e.Value == z)));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.