Ok, I'm trying to learn something new and I've been following along this how-to video on dynamic data. Everything was going along fine and I do my debugging as shown in the video. The author's code worked but mine does not. I have mirrored everything
step by step as shown. The error I get is this:
There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages.
Global.asax
<%@ Application Language="C#" %>
<%@ Import Namespace="System.ComponentModel.DataAnnotations" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Web.DynamicData" %>
<%@ Import Namespace="System.Web.UI" %>
<script RunAt="server">
private static MetaModel s_defaultModel = new MetaModel();
public static MetaModel DefaultModel {
get {
return s_defaultModel;
}
}
public static void RegisterRoutes(RouteCollection routes) {
MetaModel model = new MetaModel();
model.RegisterContext(typeof(NorthwindDataContext),
new ContextConfiguration() { ScaffoldAllTables = true });
// The following statement supports separate-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using separate pages. To enable this mode, uncomment the following
// route definition, and comment out the route definitions in the combined-page mode section that follows.
routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = DefaultModel
});
// The following statements support combined-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using the same page. To enable this mode, uncomment the
// following routes and comment out the route definition in the separate-page mode section above.
//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
// Action = PageAction.List,
// ViewName = "ListDetails",
// Model = DefaultModel
//});
//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
// Action = PageAction.Details,
// ViewName = "ListDetails",
// Model = DefaultModel
//});
}
private static void RegisterScripts() {
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
{
Path = "~/Scripts/jquery-1.7.1.min.js",
DebugPath = "~/Scripts/jquery-1.7.1.js",
CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js",
CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.js",
CdnSupportsSecureConnection = true,
LoadSuccessExpression = "window.jQuery"
});
}
void Application_Start(object sender, EventArgs e) {
RegisterRoutes(RouteTable.Routes);
RegisterScripts();
}
</script>
public static void RegisterRoutes(RouteCollection routes) {
MetaModel model = new MetaModel();
model.RegisterContext(typeof(NorthwindDataContext),
new ContextConfiguration() { ScaffoldAllTables = true });
// The following statement supports separate-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using separate pages. To enable this mode, uncomment the following
// route definition, and comment out the route definitions in the combined-page mode section that follows.
routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = DefaultModel
});
you are iinitialising model when you shoudl be initialising DefaultModel.
Just strip out this code
MetaModel model = new MetaModel();
and use the DefaultModel :)
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Ok, I made the changes you recommended but now I'm getting a different error entirely:
Compiler Error Message: CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Data'
(are you missing an assembly reference?)
Source Error:
Line 12: namespace DynamicDataSite.App_Code
Line 13: {
Line 14: using System.Data.Linq;
Line 15: using System.Data.Linq.Mapping;
Line 16: using System.Data;
Source File: d:\Projects\DynamicDataSite\DynamicDataSite\App_Code\Northwind.designer.cs Line: 14
I think this error is fooey because VS2012 built the Northwind.designer.cs file:
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18408
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DynamicDataSite.App_Code
{
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;
As you can see, it is referenced in the file and it doesn't have the red squiggly nonsense.
This is down right irritating. I fix one problem and gain another.
System.ArgumentException was unhandled by user code HResult=-2147024809 Message=The context type 'DynamicDataSite._Default' is not supported.
Source=System.Web.DynamicData StackTrace: at System.Web.DynamicData.MetaModel.RegisterContext(Func`1 contextFactory, ContextConfiguration configuration) at System.Web.DynamicData.MetaModel.RegisterContext(Type contextType, ContextConfiguration configuration)
at DynamicDataSite.Global.RegisterRoutes(RouteCollection routes) in d:\Projects\DynamicDataSite\DynamicDataSite\Global.asax.cs:line 38 at DynamicDataSite.Global.Application_Start(Object sender, EventArgs e) in d:\Projects\DynamicDataSite\DynamicDataSite\Global.asax.cs:line
80 InnerException:
Global.asax
using System;
using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.DynamicData;
using System.Web.Routing;
using System.Web.UI;
namespace DynamicDataSite
{
public class Global : System.Web.HttpApplication
{
private static MetaModel s_defaultModel = new MetaModel();
public static MetaModel DefaultModel
{
get
{
return s_defaultModel;
}
}
public static void RegisterRoutes(RouteCollection routes)
{
// IMPORTANT: DATA MODEL REGISTRATION
// Uncomment this line to register an ADO.NET Entity Framework model for ASP.NET Dynamic Data.
// Set ScaffoldAllTables = true only if you are sure that you want all tables in the
// data model to support a scaffold (i.e. templates) view. To control scaffolding for
// individual tables, create a partial class for the table and apply the
// [ScaffoldTable(true)] attribute to the partial class.
// Note: Make sure that you change "YourDataContextType" to the name of the data context
// class in your application.
// See http://go.microsoft.com/fwlink/?LinkId=257395 for more information on how to register Entity Data Model with Dynamic Data
//DefaultModel.RegisterContext(() =>
//{
// return ((IObjectContextAdapter)new YourDataContextType()).ObjectContext;
//}, new ContextConfiguration() { ScaffoldAllTables = false });
// The following registration should be used if YourDataContextType does not derive from DbContext
DefaultModel.RegisterContext(typeof(_Default), new ContextConfiguration() { ScaffoldAllTables = true });
// The following statement supports separate-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using separate pages. To enable this mode, uncomment the following
// route definition, and comment out the route definitions in the combined-page mode section that follows.
routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
{
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = DefaultModel
});
// The following statements support combined-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using the same page. To enable this mode, uncomment the
// following routes and comment out the route definition in the separate-page mode section above.
//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
// Action = PageAction.List,
// ViewName = "ListDetails",
// Model = DefaultModel
//});
//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
// Action = PageAction.Details,
// ViewName = "ListDetails",
// Model = DefaultModel
//});
}
private static void RegisterScripts()
{
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
{
Path = "~/Scripts/jquery-1.7.1.min.js",
DebugPath = "~/Scripts/jquery-1.7.1.js",
CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js",
CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.js",
CdnSupportsSecureConnection = true,
LoadSuccessExpression = "window.jQuery"
});
}
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
RegisterScripts();
}
}
}
Arghhh, one step forward, two back. This crap is annoying. I click on the Table Name link and get an error on page http://localhost:64152/DynamicDataWebsite/Orders/List.aspx
Server Error in '/DynamicDataWebsite' Application.
--------------------------------------------------------------------------------
Unable to cast object of type 'DynamicDataWebsite.NorthwindDataContext' to type 'System.Data.Objects.ObjectContext'.
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.InvalidCastException: Unable to cast object of type 'DynamicDataWebsite.NorthwindDataContext' to type 'System.Data.Objects.ObjectContext'.
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:
[InvalidCastException: Unable to cast object of type 'DynamicDataWebsite.NorthwindDataContext' to type 'System.Data.Objects.ObjectContext'.]
System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +690
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments, Creator qbConstructor) +164
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +192
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5472; ASP.NET Version:2.0.50727.5459
That project template should be a simple as adding an entity Framwork Data model editing the Global.asax.cs witht he model name and setting ScffoldColumns to true and it should just runf then I have don it literally hundreds of times.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
public static void RegisterRoutes(RouteCollection routes) {
MetaModel model = new MetaModel();
model.RegisterContext(typeof(NorthwindDataContext),
new ContextConfiguration() { ScaffoldAllTables = true });
// The following statement supports separate-page mode, where the List, Detail, Insert, and
// Update tasks are performed by using separate pages. To enable this mode, uncomment the following
// route definition, and comment out the route definitions in the combined-page mode section that follows.
routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = DefaultModel
});
you are iinitialising model when you shoudl be initialising DefaultModel.
Just strip out this code
MetaModel model = new MetaModel();
and use the DefaultModel :)
This is what did it for me after I re-created the project from scratch.
OK it was the Global.asax.cs you made a change to :) you said you had to make a change to the web.config that was what threw me :) clad you are working. Any questions and I 'm here.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
All-Star
35218 Points
9955 Posts
Moderator
Dynamic Data How-to: no accessible tables?
Jan 09, 2014 10:25 AM|bbcompent1|LINK
Ok, I'm trying to learn something new and I've been following along this how-to video on dynamic data. Everything was going along fine and I do my debugging as shown in the video. The author's code worked but mine does not. I have mirrored everything step by step as shown. The error I get is this:
There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages.
Global.asax
How To Video: http://www.asp.net/web-forms/videos/aspnet-dynamic-data/your-first-scaffold-and-what-is-dynamic-data
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 09, 2014 04:42 PM|sjnaughton|LINK
OK a sinple issue see your code here
you are iinitialising model when you shoudl be initialising DefaultModel.
Just strip out this code
MetaModel model = new MetaModel();
and use the DefaultModel :)
Always seeking an elegant solution.
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 09, 2014 04:54 PM|sjnaughton|LINK
remember the videos are OLD .Net 3.51 the principals are the same but the plumbing has changed :)
the old project template declared the Metamodel like this:
and now it is declared like this:
it's always worth comparing what the video shows with a vanila Project created with the latest version of Visual Studio
Always seeking an elegant solution.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 07:09 AM|bbcompent1|LINK
I'll give this a try and get back to you, thanks!
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 07:52 AM|bbcompent1|LINK
Ok, I made the changes you recommended but now I'm getting a different error entirely:
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 07:53 AM|bbcompent1|LINK
I think this error is fooey because VS2012 built the Northwind.designer.cs file:
As you can see, it is referenced in the file and it doesn't have the red squiggly nonsense.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 08:05 AM|bbcompent1|LINK
This is down right irritating. I fix one problem and gain another.
System.ArgumentException was unhandled by user code HResult=-2147024809 Message=The context type 'DynamicDataSite._Default' is not supported.
Source=System.Web.DynamicData StackTrace: at System.Web.DynamicData.MetaModel.RegisterContext(Func`1 contextFactory, ContextConfiguration configuration) at System.Web.DynamicData.MetaModel.RegisterContext(Type contextType, ContextConfiguration configuration) at DynamicDataSite.Global.RegisterRoutes(RouteCollection routes) in d:\Projects\DynamicDataSite\DynamicDataSite\Global.asax.cs:line 38 at DynamicDataSite.Global.Application_Start(Object sender, EventArgs e) in d:\Projects\DynamicDataSite\DynamicDataSite\Global.asax.cs:line 80 InnerException:
Global.asax
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 08:11 AM|bbcompent1|LINK
Easiest way to fix this was to use asp.net 3.5. Now the sample seems to work better.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 08:16 AM|bbcompent1|LINK
Arghhh, one step forward, two back. This crap is annoying. I click on the Table Name link and get an error on page http://localhost:64152/DynamicDataWebsite/Orders/List.aspx
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 11:08 AM|sjnaughton|LINK
Are you using the Dynamic Data Project Template to test this?
Always seeking an elegant solution.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 11:51 AM|bbcompent1|LINK
Yes I am.
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 12:17 PM|sjnaughton|LINK
OK What version of Visual Studio?
Always seeking an elegant solution.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 12:27 PM|bbcompent1|LINK
Visual Studio 2012 Professional
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 07:16 PM|sjnaughton|LINK
That project template should be a simple as adding an entity Framwork Data model editing the Global.asax.cs witht he model name and setting ScffoldColumns to true and it should just runf then I have don it literally hundreds of times.
Always seeking an elegant solution.
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 10, 2014 07:17 PM|sjnaughton|LINK
e-mail me direct and we'll walk through, if your in the UK we coudl skype :)
Always seeking an elegant solution.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 13, 2014 03:15 PM|bbcompent1|LINK
I'll try it again going at it just with the template and no modifications.
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 13, 2014 03:25 PM|sjnaughton|LINK
great let me know how you get on maybe I need to think of doing some startup videos for DD :)
Always seeking an elegant solution.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 15, 2014 09:02 AM|bbcompent1|LINK
SJ, I'm good man. Redid the project from scratch, made the one little change to the web.config and all is working good. :)
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 15, 2014 09:06 AM|sjnaughton|LINK
What did you need to chang ein the web.config?
Always seeking an elegant solution.
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 15, 2014 09:36 AM|bbcompent1|LINK
Scaffold all tables = true like you told me to :)
All-Star
35218 Points
9955 Posts
Moderator
Re: Dynamic Data How-to: no accessible tables?
Jan 15, 2014 09:37 AM|bbcompent1|LINK
This is what did it for me after I re-created the project from scratch.
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data How-to: no accessible tables?
Jan 15, 2014 10:00 AM|sjnaughton|LINK
OK it was the Global.asax.cs you made a change to :) you said you had to make a change to the web.config that was what threw me :) clad you are working. Any questions and I 'm here.
Always seeking an elegant solution.