私はこれを理解することはできません。GenreID を渡して、対応するジャンルのオブジェクトのリストを取得したい。つまり、MyGenre.RockAndRoll を渡すと、RockAndRoll オブジェクトのリストが必要になる。
Public Enum MyGenre 代替 = 0 rockAndRoll = 1 国 = 2 End Enum
Public Interface IGenre
Inherits IDisposable
Property title As String
Property artist As String
Property duration As Decimal
Property rating As Integer
Sub Listen()
End Interface
Public Class RockAndRoll
Implements IGenre
Public Property artist As String Implements IGenre.artist
Public Property duration As Decimal Implements IGenre.duration
Public Property rating As Integer Implements IGenre.rating
Public Property title As String Implements IGenre.title
Public Sub Listen() Implements IGenre.Listen
'...
End Sub
#Region "IDisposable Support"
'...
#End Region
End Class
Public Class Country
Implements IGenre
Public Property artist As String Implements IGenre.artist
Public Property duration As Decimal Implements IGenre.duration
Public Property rating As Integer Implements IGenre.rating
Public Property title As String Implements IGenre.title
Public Sub Listen() Implements IGenre.Listen
'...
End Sub
#Region "IDisposable Support"
'...
#End Region
End Class
Public Function GetAlternativeList() As IEnumerable(Of IGenre)
Return GetIGenreList(MyGenre.alternative)
End Function
Public Function GetrockAndRollList() As IEnumerable(Of IGenre)
Return GetIGenreList(MyGenre.alternative)
End Function
Public Function GetIGenreList(p_MyGenre As MyGenre) As IEnumerable(Of IGenre)
Using db As New OracleDataContext
Return (From s In db.SongList
Where s.Genre= MyGenre _
Select CType(Activator.CreateInstance(p_MyGenre.GetGenreType,
New With {.title = s.title, .artist = p1.artist, etc etc etc}), p_MyGenre.GetGenreTyp)).ToList
End Using
End Function
<Extension()> _
Private Function GetGenreType(p_formatID As MyGenre) As Type
Select Case p_formatID
Case MyGenre.rockAndRoll
Return GetType(RockAndRoll)
Case MyGenre.country
Return GetType(PlayawayView)
Case Else
Return Nothing
End Select
End Function
#
編集
#わかりやすくするために、追加の例を追加したいと思います。最初のものは紛らわしいです。これをフォーマットの観点から見てみましょう。
製品 (DVD、CD、Blu-Ray など) のリストを返したいのですが、各形式には独自の内部クラスがあります (アートワークのサイズ、処理、合法性の理由など)。
Class CD -> Implments IProduct
Class DVD -> Implements IProduct
Class BLURAY -> Implements IProduct
i.e. dim MyList = (from p in MyProductTable select p).tolist
returns 4 records.
(0)
title: Motown Unmixed
artist: Various
duration: 36:25
format: CD
upc: 024543246157
(1)
title: Classical Bytes - Bach
artist: Various
duration: 54:32
format: CD
upc: 709387901743
(2)
title: Star Wars: Episode VI - Return of the Jedi
artist: null
duration: 136.00
format: DVD
upc: 883928446172
(3)
title: Perfect Stranger
artist: null
duration: 95.36
format: BLU
upc: 043215190627
私が欲しいのは、リスト IPRODUCT です。これは、データベースを 3 回 (フォーマットの種類ごとに) ヒットすることで実行できます。結果を IPRODUCT リストに追加します。
dim MyProductList as new List(of IProduct)
MyProductList.addrange((from p in MyProductTable where p.format = "CD" select new CD with {.title = p.title, etc etc etc}).tolist)
MyProductList.addrange((from p in MyProductTable where p.format = "DVD" select new DVD with {.title = p.title, etc etc etc}).tolist)
MyProductList.addrange((from p in MyProductTable where p.format = "BLU" select new BLURAY with {.title = p.title, etc etc etc}).tolist)
上記の 3 つのクエリを 1 つのクエリに統合したいと考えています。このクエリは、CD、DVD、および BLURAY オブジェクトのリストを返します。