Reputation: 1205
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.
public int ItemID{ get; set; }
public string Cover { get; set; }
public List<SlideModel> Slides { get; set; }
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
Upvotes: 0
Views: 75
Reputation: 2245
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();
Upvotes: 1