嗨我在將數組轉換爲通用列表時遇到了問題。它引發錯誤如下。在班上我已經以ToList的形式返回,但爲什麼我仍然會出現。我已經將服務引用返回類型更改爲泛型列表默認情況下是數組,但它獲取System.Collection.GenericList無法轉換爲System.Collection.Genericlist。請幫助謝謝無法將數組轉換爲通用列表
Public Function GetMerchantList() As List(Of Merchant) Implements IMerchant.GetMerchantList
Dim ws As New aMerchantService.MerchantServiceClient
Dim General As New General
Dim kWSUrl As String = ""
Dim endpointAddress = ws.Endpoint.Address
Dim newEndpointAddress As New EndpointAddressBuilder(endpointAddress)
kWSUrl = General.ConvertWsURL("App")
newEndpointAddress.Uri = New Uri(kWSUrl & "MerchantService.svc")
ws = New aMerchantService.MerchantServiceClient("BasicHttpBinding_IMerchantService", newEndpointAddress.ToEndpointAddress())
Dim Data = ws.GetMerchantList()
Return Data
End Function
商人類
Public Function GetMerchantList() As List(Of Merchant)
Dim Db As New TTMSEntities
Dim Data = (From p In Db.TT_MERCHANT Join r In Db.TT_BRANCH_SETTING On _
p.MERCHANT_BRANCH_INTERNAL_NUM Equals r.INTERNAL_NUM _
Select New Merchant With {.MerchantID = p.MERCHANT_ID,
.MerchantName = p.DESCRIPTION,
.BranchID = r.INTERNAL_NUM,
.BranchName = r.BRANCH_DESC})
If Data IsNot Nothing Then
Return Data.ToList
' Return ConvertMerchant(Data.ToList)
Else
Return Nothing
End If
End Function
錯誤
The error is Error Value of type '1-dimensional array of TTMS.App.WebSites.Data.Merchant' cannot be converted to 'System.Collections.Generic.List(Of TTMS.Web.WebSites.WCF.Merchant)'.
有兩個問題:首先,你不能返回一個'T []數組'當聲明方法返回'名單(共T) '。第二個:你的'Merchant'類命名空間不同。 – MarcinJuraszek
'TTMS.App.WebSites.Data.Merchant'不等於'TTMS.Web.WebSites.WCF.Merchant'。 –
發佈'ws.GetMerchantList()'的代碼。 –