gpt4 book ai didi

vb.net - 使用 Entity Framework 返回列表, 'System.Collections.Generic.List cannot be converted to ' 一维数组

转载 作者:行者123 更新时间:2023-12-02 22:43:19 25 4
gpt4 key购买 nike

我在网络方法中返回列表时遇到问题。这是代码

<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)()

Dim context As New PPEntities

Return context.getTypeDetailsByParentName(para_parents).ToList()

context.Dispose()

End Function

错误是

Value of type 'System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)'

最佳答案

您的方法声明表明您正在返回一个列表数组:

List(Of getTypeDetailsByParentName_Result)()

如果您不想返回列表数组,请删除末尾的括号。然后你将只返回一个列表。


顺便说一句,您的 context.Dispose() 将永远不会被调用,因为您在此之前使用 Return 离开了该函数。不正确地清理资源可能会导致 future 出现问题。通常你可以用 Using statement 来处理这个问题:

<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)
Using context As New PPEntities
Return context.getTypeDetailsByParentName(para_parents).ToList()
End Using
End Function

关于vb.net - 使用 Entity Framework 返回列表, 'System.Collections.Generic.List cannot be converted to ' 一维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10435872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com