【发布时间】:2013-12-11 04:21:52
【问题描述】:
您好,我在将数组转换为通用列表时遇到了问题。它引发了如下错误。在课堂上,我已经以 ToList 的身份返回,但为什么我仍然会出现。我已经将服务引用返回类型更改为通用列表,默认情况下是 Array,但它获取 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)'.
【问题讨论】:
-
有两个问题:首先,当方法声明返回
List(Of T)时,不能返回T[]数组。第二个:你的Merchant类命名空间不同。 -
TTMS.App.WebSites.Data.Merchant不等于TTMS.Web.WebSites.WCF.Merchant。 -
发布
ws.GetMerchantList()的代码。 -
@KarlAnderson 我已经更新了代码,请看一下。谢谢