Khandokar Mahmud
Khandokar Mahmud

Reputation: 21

LINQ query doesn't compile

Partial Class ProtectedContent_Books Inherits System.Web.UI.Page

    Private database As BooksDataContext()


    Protected Sub authorsLinqDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles authorsLinqDataSource.Selecting
        e.Result =
        From author In database.Authors
        Select Name = author.FirstName & " " & author.LastName, author.AuthorID()
    End Sub
End Class

when I code From author In database.Authors it says Authors is not a member of System.Array!

Upvotes: 2

Views: 53

Answers (1)

Markus
Markus

Reputation: 22446

The problem is that by

Private database As BooksDataContext()

you declare an array of BooksDataContext objects. I suspect you want to do:

Private database As New BooksDataContext()

This only declares one new instance of BooksDataContext. You might also want to check the SELECT part of your query as it will not compile. If you want to select a new anonymous object, change your query as follows:

e.Result = From author In database.Authors
    Select New With { .Name = author.FirstName & " " & author.LastName, 
                      .AuthorId =  author.AuthorID }

This link shows a sample on how to use the event.

Upvotes: 1

Related Questions