WCF EF返回列表

时间:2013-12-09 05:47:48

标签: vb.net wcf entity-framework

嗨我在返回EF作为列表时遇到错误。这是我的代码。

WCF

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
                Else
                    Return Nothing
                End If
 End Function
  

错误是类型' 1维数组的错误值   TTMS.App.WebSites.Data.Merchant'无法转换为   ' System.Collections.Generic.List(Of TTMS.Web.WebSites.WCF.Merchant)'。

请帮忙。感谢

1 个答案:

答案 0 :(得分:2)

看起来您正在使用服务参考。默认情况下,WCF会将通用列表序列化为数组。要覆盖此行为,当您添加服务引用时,请单击左下角的“高级”按钮。这将打开服务参考设置。选择System.Generics.List作为集合类型(默认为System.Array):

enter image description here