我有以下類別: -多到許多與LINQ
Blog.cs
public int BlogId { get; set; }
public string BlogTitle { get; set; }
public virtual ICollection<BlogTag> BlogTags { get; set; }
和
BlogTag.cs
public int BlogTagId { get; set; }
public string BlogTagName { get; set; }
public Blog Blog { get; set; }
public int BlogId { get; set; }
現在我需要包含BlogTagName博客的名單,所以我嘗試以下,但它不能正常工作: -
var tags = viewModel.BlogViewModel.BlogList.Where(post => post.BlogTags.All(tag => tag.BlogTagName.Contains(tagName)));
我怎樣才能得到這個工作?
感謝
我覺得造型可以稍微進行重構。如果它很多,BlogTag類不應該有一個Blog。 Theoritically,你可以相當有一個List。取決於你是否總是要自上而下查詢。 –