キャストとインターフェイスに問題があります。以下は私が使用しているコードです。エラーの内容私は何が起こっているのか完全に理解していません。私は、インターフェイスを実装するアイテムのリストを作成した場合、インターフェイスを実装する別のアイテムを渡すと動作するはずだと考えました。しかし、それはしません。誰かがなぜそれができないのか、私は代わりに何をすべきかを説明することができますか?ありがとうございましたvbインターフェイスとlinq-to-sql
エラーラインには、それを識別する3つのastrixがあります。タイプ 「System.Data.Linqの オブジェクトをキャストすることができません:再び
どうもありがとうございましタイプ 「System.InvalidCastExceptionの」の未処理の例外は、DAL.dll で追加情報を起こりました。 DataQuery
1[BuisnessObjects.Project]' to type 'System.Collections.Generic.IEnumerable
1 [BuisnessObjects.IProject]」
Imports BuisnessObjects
Public Class ProjectInfoRepository
Implements IProjectInfoRepository
Function GetAllProjects() As List(Of BuisnessObjects.IProject) Implements IProjectInfoRepository.GetAllProjects
Dim returnList As New List(Of BuisnessObjects.IProject)
***returnList.AddRange(From p In DC.ProjectInfos _
Select New BuisnessObjects.Project() With {.ProjectID = p.projectID, .ProjectName = p.projectName})***
Return returnList
End Function
End Class
Public Class Project
Implements IProject
Private _projectName As String
Property ProjectName() As String Implements IProject.ProjectName
Get
Return _projectName
End Get
Set(ByVal value As String)
_projectName = value
End Set
End Property
Private _projectID As Integer
Property ProjectID() As Integer Implements IProject.ProjectID
Get
Return _projectID
End Get
Set(ByVal value As Integer)
_projectID = value
End Set
End Property
End Class
Public Interface IProject
Property ProjectName() As String
Property ProjectID() As Integer
End Interface
なぜ私はそれをキャストしなければならないかと思います。なぜあなたはどうか説明できますか?また、助けてくれてありがとう、それは働いた – gh9