0

我有一个 sp 添加到我的 linq 设计器中,它生成了结果类:

Partial Public Class web_GetTweetsByUserIDResult

    Private _userid As Integer

    Private _tweetid As Integer

    Private _TweeterFeed As String

    Public Sub New()
        MyBase.New
    End Sub

    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_userid", DbType:="Int NOT NULL")>  _
    Public Property userid() As Integer
        Get
            Return Me._userid
        End Get
        Set
            If ((Me._userid = value)  _
                        = false) Then
                Me._userid = value
            End If
        End Set
    End Property

    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_tweetid", DbType:="Int NOT NULL")>  _
    Public Property tweetid() As Integer
        Get
            Return Me._tweetid
        End Get
        Set
            If ((Me._tweetid = value)  _
                        = false) Then
                Me._tweetid = value
            End If
        End Set
    End Property

    <Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_TweeterFeed", DbType:="NVarChar(100)")>  _
    Public Property TweeterFeed() As String
        Get
            Return Me._TweeterFeed
        End Get
        Set
            If (String.Equals(Me._TweeterFeed, value) = false) Then
                Me._TweeterFeed = value
            End If
        End Set
    End Property
End Class

但是,在我尝试使用结果类的“TweeterFeed”成员的这一段代码中,我收到错误消息,“错误 4 'TweeterFeed' 不是 'System.Data.Linq.ISingleResult(Of web_GetTweetsByUserIDResult)'。”

我在本节中的代码是:

<WebMethod()> _
    Public Function GetTweetsByUserID(ByVal userID As Integer) As List(Of SimpleTweet)
        Dim result As New List(Of SimpleTweet)
        Dim urlTwitter As String = "https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name={0}&count=20"
        Dim lq As New lqDFDataContext
        Dim var = lq.web_GetTweetsByUserID(userID).ToList()
        If Not var Is Nothing Then
            For Each twitterfeed In var

                Dim listURL As String = String.Format(urlTwitter, var.TweeterFeed)

                Dim tweetXML As XmlDocument = utils.GetXMLForURL(listURL)

                Dim tweetnodelist As XmlNodeList = tweetXML.ChildNodes(1).ChildNodes

                For Each node As XmlNode In tweetnodelist
                    Dim tweet As New SimpleTweet
                    tweet.CreatedAt = node.SelectSingleNode("created_at").InnerText
                    tweet.HTMLText = utils.ReturnTextWithHRefLink(node.SelectSingleNode("text").InnerText)
                    tweet.ID = node.SelectSingleNode("id").InnerText
                    tweet.Name = node.SelectSingleNode("user/name").InnerText
                    tweet.ScreenName = node.SelectSingleNode("user/screen_name").InnerText
                    tweet.Text = node.SelectSingleNode("text").InnerText
                    tweet.UserID = node.SelectSingleNode("user/id").InnerText
                    tweet.ProfileImageURL = node.SelectSingleNode("user/profile_image_url_https").InnerText
                    result.Add(tweet)
                Next
            Next
        End If
        Return result
    End Function

有谁知道发生了什么?据我所知,“TweeterFeed”显然是该课程的成员,我不知道为什么会出现此错误。

4

2 回答 2

2

你在var.TweeterFeed应该使用的时候使用twitterFeed.TweeterFeedtwitterFeed是从中提取var结果,是一系列结果。

使用更具描述性的变量名称var可能会使您更清楚:)

于 2012-08-15T14:02:00.860 回答
0

我有这门课

Public Class Tamano
    Private pWidth As Integer
    Private pHeight As Integer
    Public Property Width As Integer
    Public Property Height As Integer
End Class

'Height' is not a member of 'Tamaño'在 IIS 中收到编译错误消息

要修复它,请将 Set 和 Get 添加到属性并编译。

Public Class Tamano
    Private pWidth As Integer
    Private pHeight As Integer
    Public Property Width As Integer
        Get
            Return pWidth
        End Get
        Set(value As Integer)
            pWidth = value
        End Set
    End Property
    Public Property Height As Integer
        Get
            Return pHeight
        End Get
        Set(value As Integer)
            pHeight = value
        End Set
    End Property
End Class

这可能与您的问题没有直接关系,但可能对其他人有所帮助。

于 2016-07-19T22:07:31.093 回答