I have the following classes :-
Blog.cs
public int BlogId { get; set; }
public string BlogTitle { get; set; }
public virtual ICollection<BlogTag> BlogTags { get; set; }
and
BlogTag.cs
public int BlogTagId { get; set; }
public string BlogTagName { get; set; }
public Blog Blog { get; set; }
public int BlogId { get; set; }
Now I need to get a list of Blogs that contain the BlogTagName, so I tried the following but it is not working properly:-
var tags = viewModel.BlogViewModel.BlogList.Where(post => post.BlogTags.All(tag => tag.BlogTagName.Contains(tagName)));
How can I get this working?
Thanks
replace All
by Any
sould do the trick
This will check if "at least one" blockTag of the blog contains your tagName.
With All
, all of the blockTags from a blog should contain your tagName.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.