2013-10-11 3 views
0

Брусом Выяснить Что ПроблемаLinq Проблема запроса с анонимными типами

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>)'. 

ответ

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) 
+0

было это полезно или нет? – Ric

Смежные вопросы