0

无法弄清楚是什么问题

If IsNothing(_cartItem) Then

    Dim SPDB As New SamplePicturesDataContext()
    Dim q = From sp In SPDB.Pictures _
            Where sp.Id = ItemId _
            Select New With {.Pic_Desc = sp.Description, _
                             .Pic_Title = sp.PictureName}
    _cartItem = New CartItem(q.Pic_Desc, 1, q.Pic_Title)
Else


Error   1   'Pic_Desc' is not a member of 'System.Linq.IQueryable(Of <anonymous type>)'.    

Error   2   'Pic_Title' is not a member of 'System.Linq.IQueryable(Of <anonymous type>)'.   
4

1 回答 1

1

因为类型是IQueryable您需要枚举查询,以便对其进行评估然后可以使用它。

这应该有效(注意我不检查Nothing你应该做什么):

Dim SPDB As New SamplePicturesDataContext()
    Dim q = (From sp In SPDB.Pictures _
            Where sp.Id = ItemId _
            Select New With {.Pic_Desc = sp.Description, _
                             .Pic_Title = sp.PictureName}).SingleOrDefault() ' assume singleordefault due to matching on id values.

    _cartItem = New CartItem(q.Pic_Desc, 1, q.Pic_Title)
于 2013-10-11T11:17:50.353 回答