Everything I've seen says that you set { ScaffoldAllTables = false } in Global.asax then you create a partial empty class for your entity with [ScaffoldTable(true)] and that will only show that table in the list. However that's not what happened. Instead
all the tables still show. Now there is in Default.cs code generated by default that binds all visible tables to the Menu. I would have thought this gets overriden.
What I ended up doing was filtering the visible tables list to the one table I want showing.
However, it seems I would have to keep adding more and more tables when this should be automatic, no?
using System;
using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.DynamicData;
using System.Web.Routing;
using NotAClue.Web.DynamicData;
namespace Manager
{
public class Global : System.Web.HttpApplication
{
private static MetaModel s_defaultModel = new AdvancedMetaModel();
public static MetaModel DefaultModel
{
get
{
return s_defaultModel;
}
}
public static void RegisterRoutes(RouteCollection routes)
{
DefaultModel.RegisterContext(typeof(MiscDataDataContext), new ContextConfiguration() { ScaffoldAllTables = false });
routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
{
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = DefaultModel
});
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
});
}
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
}
}
This is Default page Load -- I shouldn't have to filter the table list like this:
protected void Page_Load(object sender, EventArgs e)
{
System.Collections.IList visibleTables = Global.DefaultModel.VisibleTables.Where(t => t.Name == "MYTABLENAME").ToList();
if (visibleTables.Count == 0)
{
throw new InvalidOperationException("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.");
}
Menu1.DataSource = visibleTables;
Menu1.DataBind();
}
Here's my table class to scaffold:
[ScaffoldTable(true)]
public partial class MYTABLENAME
{
}
Somthing seems badly broken on you computer try this on another PC please, I cannot repro this I build DD apps all the time and I have never com accross this issue.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
OK, so I think I see what the problem is. My partial table class is not being recognized, this is my model class to which I add the custom code, but this has to be part of the main table class assembly. And it's because the main part of the table object
class is defined in another project and partial classes can only be defined within the same project. This means that I cannot use Plinqo, or at least I cannot use the instance of plinqo defined in the data obeject of my solution. I would either need to have
a second plinqo generator in this new project or I would have to use the standard project template and generate my own orm thru linq to sql. :)
Hi IAmTheWalrus, your partial class must be in the same namespce and assembly for it to be recognised, so if your datamodel is in a seperate project then you buddy class must be in the same project,
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Thanks. Unfortunately the data namespace is under .Net 3.5 which doesn't have the newer features I want to use in metedata. What I have done id just added a dbml in my dd project, this works untill entire solution goes to .net 4+
IAmTheWalrus
Member
31 Points
24 Posts
After setting { ScaffoldAllTables = false }, all tables still show.
Dec 22, 2012 03:39 PM|LINK
Everything I've seen says that you set { ScaffoldAllTables = false } in Global.asax then you create a partial empty class for your entity with [ScaffoldTable(true)] and that will only show that table in the list. However that's not what happened. Instead all the tables still show. Now there is in Default.cs code generated by default that binds all visible tables to the Menu. I would have thought this gets overriden.
What I ended up doing was filtering the visible tables list to the one table I want showing.
However, it seems I would have to keep adding more and more tables when this should be automatic, no?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 23, 2012 06:09 AM|LINK
Hi,
Can you show us your full codes of cs?
IAmTheWalrus
Member
31 Points
24 Posts
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 24, 2012 02:42 PM|LINK
here it is: This is Global.asax
using System; using System.ComponentModel.DataAnnotations; using System.Web; using System.Web.DynamicData; using System.Web.Routing; using NotAClue.Web.DynamicData; namespace Manager { public class Global : System.Web.HttpApplication { private static MetaModel s_defaultModel = new AdvancedMetaModel(); public static MetaModel DefaultModel { get { return s_defaultModel; } } public static void RegisterRoutes(RouteCollection routes) { DefaultModel.RegisterContext(typeof(MiscDataDataContext), new ContextConfiguration() { ScaffoldAllTables = false }); routes.Add(new DynamicDataRoute("{table}/{action}.aspx") { Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }), Model = DefaultModel }); 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 }); } void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } } }This is Default page Load -- I shouldn't have to filter the table list like this:
protected void Page_Load(object sender, EventArgs e) { System.Collections.IList visibleTables = Global.DefaultModel.VisibleTables.Where(t => t.Name == "MYTABLENAME").ToList(); if (visibleTables.Count == 0) { throw new InvalidOperationException("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."); } Menu1.DataSource = visibleTables; Menu1.DataBind(); }Here's my table class to scaffold:
[ScaffoldTable(true)] public partial class MYTABLENAME { }what am I missing??
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 27, 2012 09:40 AM|LINK
Somthing seems badly broken on you computer try this on another PC please, I cannot repro this I build DD apps all the time and I have never com accross this issue.
Always seeking an elegant solution.
IAmTheWalrus
Member
31 Points
24 Posts
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 27, 2012 03:18 PM|LINK
OK, so I think I see what the problem is. My partial table class is not being recognized, this is my model class to which I add the custom code, but this has to be part of the main table class assembly. And it's because the main part of the table object class is defined in another project and partial classes can only be defined within the same project. This means that I cannot use Plinqo, or at least I cannot use the instance of plinqo defined in the data obeject of my solution. I would either need to have a second plinqo generator in this new project or I would have to use the standard project template and generate my own orm thru linq to sql. :)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 28, 2012 12:40 AM|LINK
Hi,
Since your problem is found, so is your problem solved?
I come here to check and make a confirmation.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 30, 2012 03:36 PM|LINK
Hi IAmTheWalrus, your partial class must be in the same namespce and assembly for it to be recognised, so if your datamodel is in a seperate project then you buddy class must be in the same project,
Always seeking an elegant solution.
IAmTheWalrus
Member
31 Points
24 Posts
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 30, 2012 04:46 PM|LINK
Thanks. Unfortunately the data namespace is under .Net 3.5 which doesn't have the newer features I want to use in metedata. What I have done id just added a dbml in my dd project, this works untill entire solution goes to .net 4+
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 30, 2012 11:46 PM|LINK
Yes. Please upgrate to net 4.0 instead.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: After setting { ScaffoldAllTables = false }, all tables still show.
Dec 31, 2012 11:14 AM|LINK
Are you saying that the metadata is working until you switch from .Net 3.5 to .Net 4x?
Always seeking an elegant solution.