Explicit construction of entity type 'DataAccessLayer.author' in query is not allowed.

Hi experts,

What is wrong with this query

I only want to select the named columns

thnaks
protected void Page_Load(object sender, EventArgs e)
    {
       PubsDataContext context  = new PubsDataContext();
       var author = from a in context.authors
       select new author
       {
          au_id = a.au_id,
          au_lname = a.au_lname,
          au_fname= a.au_fname,
          state = a.state
       };
       GridView1.DataSource = author;
       GridView1.DataBind();
     
    }

Open in new window

SirReadAlotAsked:
Who is Participating?
 
lazyberezovskyCommented:
Remove 'author' when creating anonymous type
protected void Page_Load(object sender, EventArgs e)
    {
       PubsDataContext context  = new PubsDataContext();
       var author = from a in context.authors
       select new
       {
          au_id = a.au_id,
          au_lname = a.au_lname,
          au_fname= a.au_fname,
          state = a.state
       };
       GridView1.DataSource = author;
       GridView1.DataBind();
     
    }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.