質問

私はより一般的なものを作ることを見てきました WHERE 節だから私はコードを繰り返さないでください。私はタグに基づいて投稿を返す次のものを持っています。同じことは、検索用語やカテゴリに基づいて投稿を返すために同じように簡単に使用することができます。唯一の違いはwhere句です。だから私が見てきたことから、式ツリーや述語ビルダーを使用することができますが、これらが同じかどうかはわかりません。また、DLINQは2013年からSOのポストでnオプションでした。そしてLinqKitもオプションだと思います。誰かがより一般的なwhere句を作成するための正しい方向を指し示すことができますか?

これは私が動的にしたい部分です Where(Function(t) t.PostTag.Any(Function(t1) t1.Tag.StartsWith(tag))) そのため、Posttagの代わりにPostCategoryまたはPostsで簡単にswpaを使用できます。

コード:

Return _postRepository.SelectAll.Where(Function(t) t.PostTag.Any(Function(t1) t1.Tag.StartsWith(tag))).Select(Function(S) New be_PostsViewModel With {.IsPublished = S.PostIsPublished, .Id = S.PostId, .PostSummary = S.PostSummary, .PostDateCreated = S.PostDateCreated, .PostTitle = S.PostTitle, .PostTags = S.PostTag}).OrderByDescending(Function(d) d.PostDateCreated).Where(Function(p) p.IsPublished = True).Skip((Page - 1) * PageSize).Take(PageSize).ToList

役に立ちましたか?

解決

解決しました -

Dim PostsByTagExpression As Expression(Of Func(Of PostSummaryDTO, Boolean)) =
Function(p) p.PostTag.Any(Function(t1) t1.Tag.StartsWith(Word))

Dim postsbytag = _postRepository.SelectAll.AsExpandable.Where(PostsByTagExpression)
.Select
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top