ASP.NET MVC プロジェクトに取り組んでいます。単純なキャッシュ機能を持つリポジトリを介したデータ アクセス。次の 2 つのようないくつかの関数が含まれています。
Public Function SelectAllCurrencies() As List(Of store_Currency)
Dim AllCurrencies As List(Of store_Currency)
If UseCaching Then
AllCurrencies = HttpContext.Current.Cache("AllCurrencies")
If AllCurrencies Is Nothing Then
AllCurrencies = (From Currencies In db.Currencies Order By Currencies.Title Ascending).ToList
Cache.AddToCache("AllCurrencies", AllCurrencies)
End If
Else
AllCurrencies = (From Currencies In db.Currencies Order By Currencies.Title Ascending).ToList
End If
Return AllCurrencies
End Function
Public Function SelectAllCountries() As List(Of store_Country)
Dim AllCountries As List(Of store_Country)
If UseCaching Then
AllCountries = HttpContext.Current.Cache("AllCountries")
If AllCountries Is Nothing Then
AllCountries = (From Countries In db.Countries Order By Countries.Title Ascending).ToList
Cache.AddToCache("AllCountries", AllCountries)
End If
Else
AllCountries = (From Countries In db.Countries Order By Countries.Title Ascending).ToList
End If
Return AllCountries
End Function
ご覧のとおり、同じワークフローを何度も使用しています。この冗長性を取り除きたい。ジェネリックは解決策を提供するはずだと思いますが、ジェネリックSelectAllEntities(Of T)
関数でLINQステートメントを処理する方法を一生理解することはできません。おそらく動的LINQを使用して、クエリを「一般化」する方法はありますか?