错误说x不是y的成员,但确实如此

时间:2012-08-15 13:57:32

标签: vb.net linq linq-to-sql stored-procedures

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

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”显然是该类的成员,我无法弄清楚为什么会出现这个错误。

2 个答案:

答案 0 :(得分:2)

当您使用var.TweeterFeed时,您正在使用twitterFeed.TweeterFeedtwitterFeed是从var中提取的 结果,它是序列的结果。

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

答案 1 :(得分:0)

我有这个班级

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

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

要修复它,请将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

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