0

I have a DbSet that contains a list of Item, Now I want to search an Item from the database based on its nested list item matching.

Item Model

public int ItemID{ get; set; }
public string Cover { get; set; }
public List<SlideModel> Slides { get; set; }

Slide Model

public int SlideID{ get; set; }
public int ItemID{ get; set; }
public string Slide{ get; set; }

Now I will pass a search string of Slide and it will search for the Item who have the Slide in its List<SlideModel> and return the Item

item = await context.Items
    .Include(i => i.Slides)
    .Where(...todo-maybe...)
    .FirstOrDefaultAsync();

How should I write the Query method to get the item based on the slide

6
  • based on its nested list item matching -- Please elaborate. An example of what you want would help. Commented Sep 9, 2018 at 9:20
  • @Gert Arnold, Please see the edited question, I just want to select an item that contain the slide in its SlideList. Commented Sep 9, 2018 at 9:29
  • And where are you stuck trying this? Commented Sep 9, 2018 at 9:31
  • The query method, How should i write it to get the result? Commented Sep 9, 2018 at 9:33
  • Which criteria in where method, my friend? Commented Sep 9, 2018 at 9:35

1 Answer 1

1

That's the thing that you want? Hope to help, my friend :))

string inputSlide = "abc";

item = await context.Items
    .Include(i => i.Slides)
    .Where(i => i.Slides.Any(i => i.Slide.ToLower() == inputSlide.ToLower()))
    .FirstOrDefaultAsync();
Sign up to request clarification or add additional context in comments.

2 Comments

really helped, Thank you.
@SabirHossain: Well played, my friend :))

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.