This may be impossible to answer unless you have all information regarding the model and the web form involved. But I am going to try the simple approach first.
I started out creating an empty Web Application in VS 2010. I added a web form and placed an EntityDataSource and a GridView on the web form. The
EntitySetName of EntityDataSource is set to Customers which has a Navigation property called PrimaryActivity. The GridView's datasource is set to the
EntityDataSource. I set the Include property of the EntityDataSource to PrimaryActivity.
In order to prepare the GridView so that one can eventually edit the PrimaryActivity, I added the PrimaryActivity column to selected columns of the GridView, set that column to read only, set the DataField property to PrimaryAcitivity.Name and clicked on
the Convert this field to Template Field hyperlink.
Below is the markup I expected to be generated which agrees with the book I am using. After that is the markup VS 2010 actually generated
which causes a runtime error (see error below the 2nd markup). [When I copy and paste this markup over the VS 2010 generated markup, the application runs fine]
Could not determine a MetaTable. A MetaTable could not be determined for the data source 'EntityDataSource1' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute.
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.InvalidOperationException: Could not determine a MetaTable. A MetaTable could not be determined for the data source 'EntityDataSource1' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Could not determine a MetaTable. A MetaTable could not be determined for the data source 'EntityDataSource1' and one could not be inferred from the request URL. Make sure that the table is mapped to the dats source, or that the data source is configured with a valid context type and table name, or that the request is part of a registered DynamicDataRoute.]
System.Web.DynamicData.Util.MetaTableHelper.GetTableWithFullFallback(IDataSource dataSource, HttpContextBase context) +223462
System.Web.DynamicData.Util.MetaTableHelper.FindMetaTable(Control current, HttpContextBase context) +96
System.Web.DynamicData.DynamicDataExtensions.FindMetaTable(Control current) +65
System.Web.DynamicData.DynamicControl.get_Table() +21
System.Web.DynamicData.DynamicControl.ResolveColumn() +76
System.Web.DynamicData.DynamicControl.OnInit(EventArgs e) +33
System.Web.UI.Control.InitRecursive(Control namingContainer) +140
System.Web.UI.Control.InitRecursive(Control namingContainer) +311
System.Web.UI.Control.InitRecursive(Control namingContainer) +311
System.Web.UI.Control.AddedControl(Control control, Int32 index) +197
System.Web.UI.ControlCollection.Add(Control child) +79
System.Web.UI.WebControls.RowControlCollection.Add(Control child) +37
System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) +36
System.Web.UI.WebControls.RowControlCollection.AddAt(Int32 index, Control child) +42
System.Web.UI.WebControls.TableRowCollection.Add(TableRow row) +33
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +148
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3896
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
wrlucas
Member
355 Points
82 Posts
Unexpected generation of Dynamic Controls by VS 2010 in simple Web Application.
Nov 17, 2011 05:11 PM|LINK
Reference:
Lerman, Julia (2010-08-09). Programming Entity Framework 2nd Edition (p. 310). O'Reilly Media. Kindle Edition.
This may be impossible to answer unless you have all information regarding the model and the web form involved. But I am going to try the simple approach first.
I started out creating an empty Web Application in VS 2010. I added a web form and placed an EntityDataSource and a GridView on the web form. The
EntitySetName of EntityDataSource is set to Customers which has a Navigation property called PrimaryActivity. The GridView's datasource is set to the
EntityDataSource. I set the Include property of the EntityDataSource to PrimaryActivity.
In order to prepare the GridView so that one can eventually edit the PrimaryActivity, I added the PrimaryActivity column to selected columns of the GridView, set that column to read only, set the DataField property to PrimaryAcitivity.Name and clicked on the Convert this field to Template Field hyperlink.
Below is the markup I expected to be generated which agrees with the book I am using. After that is the markup VS 2010 actually generated
which causes a runtime error (see error below the 2nd markup). [When I copy and paste this markup over the VS 2010 generated markup, the application runs fine]
<asp:TemplateField HeaderText="PrimaryActivity" SortExpression="PrimaryActivity"> <EditItemTemplate> <asp:DropDownList runat="server" ID="act1DDL" DataSourceID="ActivityDataSource" DataTextField="Name" DataValueField="ActivityID" AppendDataBoundItems="True" SelectedValue= '<%# Bind("PrimaryActivityID") %>'> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("PrimaryActivity.Name") %>'> </asp:Label> </ItemTemplate> </asp:TemplateField>What I acuall got.
<asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="PrimaryActivity.Name" SortExpression="PrimaryActivity.Name"> <EditItemTemplate> <asp:DynamicControl ID="DynamicControl1" runat="server" DataField="PrimaryActivity.Name" Mode="Edit" /> </EditItemTemplate> <ItemTemplate> <asp:DynamicControl ID="DynamicControl1" runat="server" DataField="PrimaryActivity.Name" Mode="ReadOnly" /> </ItemTemplate> </asp:TemplateField>Could not determine a MetaTable. A MetaTable could not be determined for
the data source 'EntityDataSource1' and one could not be inferred from the
request URL. Make sure that the table is mapped to the dats source, or that the
data source is configured with a valid context type and table name, or that the
request is part of a registered DynamicDataRoute.
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.InvalidOperationException: Could not determine a MetaTable. A
MetaTable could not be determined for the data source 'EntityDataSource1' and
one could not be inferred from the request URL. Make sure that the table is
mapped to the dats source, or that the data source is configured with a valid
context type and table name, or that the request is part of a registered
DynamicDataRoute.
Source Error:
Stack Trace:Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NETVersion:4.0.30319.237
wrlucas
Member
355 Points
82 Posts
Re: Unexpected generation of Dynamic Controls by VS 2010 in simple Web Application.
Nov 17, 2011 08:47 PM|LINK
I installed SP1 for VS 2010 and this fixed the problem.