er_jack
er_jack

Reputation: 112

Object not queryable

I have a database "Pubs" with a table "authors". I have made a dbml file from the database by dragging over "authors".

Here is the "Default.aspx.vb"

Public Class _Default
    Inherits System.Web.UI.Page
    Dim author As Object
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim db As New PubsContext
        Dim authors = From p In dbo.authors _
                       Select p

        GridView1.DataSource = author
        GridView1.DataBind()
    End Sub
End Class

Here is the class for it: "Class1.vb"

Partial Public Class PubsContext
    Dim authors As Object
    Public Function GetProductsByCategory(ByVal id1 As Integer) As IEnumerable(Of authors)
        Return From p In Me.authors _
               Where p.au_id = id1 _
               Select p
    End Function
End Class

Error code: "Expression of type 'Object' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ".

In references there is already a "System.Data.Linq". What should I do?

Upvotes: 0

Views: 1800

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502076

Well this is the problem:

Dim authors As Object

That's just an object. What does it mean to call Select, Where etc on that? Where are you even giving it a value? Work out what the type should really be, make sure you give it an appropriate value to start with, and you should be fine.

It's not clear why you're introducing your own authors field at all, to be honest - I'd expect the generated context to have an Authors property of type Table<Author> or something similar.

(I note that you're also trying to set GridView1.DataSource to author rather than authors, by the way... Why are you doing that? What value are you expecting the author field in _Default to have?)

Upvotes: 3

Related Questions