How to LINWQ this ?

S

sjoshi

I have a simple Grid template that I'm trying to use with this LINQ
SQL:

from publisher in SampleData.Publishers
join book in SampleData.Books
on publisher equals book.Publisher into PublisherBooks
from book in PublisherBooks.DefaultIfEmpty(new Book { Title = "(no
books)" })
select new
{
Publisher = publisher.Name,
Books = book
};

The grid is defined as :

<asp:GridView ID="GridViewGroupJoin" AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:BoundField HeaderText="Publisher" DataField="Publisher" />
<asp:TemplateField HeaderText="Books">
<ItemTemplate>
<asp:BulletedList ID="BulletedList1" runat="server"
DataSource='<% #Eval("Books") %>' DataValueField="Title" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

But that does not work and gives this error

{"Data source is an invalid type. It must be either an IListSource,
IEnumerable, or IDataSource."}

Although the ResultsView of the query in debug shows the correct entry
as
{ Publisher = "I Publisher", Books = {(no books)} }

thanks
Sunit
 
F

Frans Bouma [C# MVP]

sjoshi said:
I have a simple Grid template that I'm trying to use with this LINQ
SQL:

from publisher in SampleData.Publishers
join book in SampleData.Books
on publisher equals book.Publisher into PublisherBooks
from book in PublisherBooks.DefaultIfEmpty(new Book { Title = "(no
books)" })
select new
{
Publisher = publisher.Name,
Books = book
};

The grid is defined as :

<asp:GridView ID="GridViewGroupJoin" AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:BoundField HeaderText="Publisher" DataField="Publisher" />
<asp:TemplateField HeaderText="Books">
<ItemTemplate>
<asp:BulletedList ID="BulletedList1" runat="server"
DataSource='<% #Eval("Books") %>' DataValueField="Title" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

But that does not work and gives this error

{"Data source is an invalid type. It must be either an IListSource,
IEnumerable, or IDataSource."}

Although the ResultsView of the query in debug shows the correct entry
as
{ Publisher = "I Publisher", Books = {(no books)} }

'SampleData' isn't of type IEnumerable, IListSource or IDataSource.

FB


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top