Hello all,
First of all, I love this book. I have learned a lot and currently in chapter 14.
I have a problem with the try out in page 481.
I am able to complete all the steps but I am getting an error in the code behind for the Alls.aspx web form.
The code in the book does not work:
-----------------------------------------------------------------
Imports PlanetWroxModel
Partial Class Reviews_All
Inherits BasePage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using myEntities As New PlanetWroxEntities()
Dim allReviews = From review In myEntities.Reviews
Where review.Authorized = True
Order By review.CreateDateTime Descending
Select review
GridView1.DataSource = allReviews
GridView1.DataBind()
End Using
End Sub
End Class-----------------------------------------------------------------
The imports works when I use PlanetWroxEntities instead of PlanetWroxModel like this:
Imports PlanetWroxEntities
Even after correcting that line, I get the following error when opening the all.aspx form:
----------------------------------------------------------------------
Server Error in '/Site' Application.
--------------------------------------------------------------------------------
Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().
Source Error:
Line 11: Select review
Line 12: GridView1.DataSource = allReviews
Line 13: GridView1.DataBind()
Line 14: End Using
Line 15: End Sub
Source File: G:\Site\Reviews\All.aspx.
vb Line: 13
Stack Trace:
[NotSupportedException: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().]
System.Data.Entity.Infrastructure.DbQuery`1.System .ComponentModel.IListSource.GetList() +57
System.Web.UI.DataSourceHelper.GetResolvedDataSour ce(Object dataSource, String dataMember) +57
System.Web.UI.WebControls.ReadOnlyDataSource.Syste m.Web.UI.IDataSource.GetView(String viewName) +42
System.Web.UI.WebControls.DataBoundControl.Connect ToDataSourceView() +145
System.Web.UI.WebControls.DataBoundControl.GetData () +4
System.Web.UI.WebControls.DataBoundControl.Perform Select() +54
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +30
System.Web.UI.WebControls.GridView.DataBind() +4
Reviews_All.Page_Load(Object sender, EventArgs e) in G:\Site\Reviews\All.aspx.
vb:13
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
----------------------------------------------------------------------
It is important to note that I am doing this in Visual Studio 2012 (the book used 2010 so this might be a potential root cause). If this there a way to make this work in 2012?
It will be painful to have to start this WroxPlanet site from scratch in 2010.
I have been looking to fix this problem for one week and have not found anything yet other than some references about how this method does not work with the new versions of the EF.
So good to have found this forum, please let me know your thoughts about this.
Many thanks in advance!