LINQ to Objects を使用して本のリストをグリッドビューにバインドしようとしています。Author と Book はカスタム オブジェクトで、"Books" は Author クラスでリストとして定義されます。
List<Author> authors = new List<Author>();
// list of authors/books is populated here
var books = from s in authors
where s.LastName == "Jones"
select s.Books;
GridView2.DataSource = books.AsEnumerable().Cast<Book>().ToList();
GridView2.DataBind();
ただし、次のエラーが表示されます。
System.Web.Services.Protocols.SoapException: サーバーは要求を処理できませんでした。--->
System.InvalidCastException: タイプのオブジェクトをキャストできません
「System.Collections.Generic.List`1[Book]」で「Book」と入力します。
System.Linq.Enumerable.d__aa
1.MoveNext() at System.Collections.Generic.List
1..ctor (IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 ソース)で
ここで何が間違っていますか?