locked
Filter Main Tables List RRS feed

  • Question

  • User-1254308814 posted

    I tried to filter the tables in the main list but I get an error. ER: The entity type System.Web.DynamicData.MetaTable does not belong to any registered model.Is there an easy way to filter the tables out fo the main view?

    Thursday, October 23, 2008 3:48 AM

Answers

  • User-330204900 posted

    Hi here's the way I did it for another thread: 

    protected void Page_Load(object sender, EventArgs e)
    {
    	System.Collections.IList visibleTables = MetaModel.Default.VisibleTables;
    	if (visibleTables.Count == 0)
    	{
    		throw new InvalidOperationException("There are no accessible tables...");
    	}
    
    	// adding your own table to the list
    	var tablesMain = from t in MetaModel.Default.VisibleTables
    					 where t.Attributes.OfType<LookupAttribute><LOOKUPATTRIBUTE>().SingleOrDefault() != null 
    					 select new MenuItem
    					 {
    						 ListActionPath = t.ListActionPath,
    						 DisplayName = t.DisplayName
    					 };
    
    	Menu1.DataSource = tablesMain;
    	Menu1.DataBind();
    }
    
     And here's the attribute: 
    [AttributeUsage(AttributeTargets.Class)]
    public class LookupAttribute : Attribute
    {
    	public Boolean LookupTable { get; private set; }
    
    	public LookupAttribute(Boolean lookupTable)
    	{
    		LookupTable = lookupTable;
    	}
    }
    Hope this helps [:D]
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 23, 2008 8:30 AM

All replies

  • User-330204900 posted

    Hi here's the way I did it for another thread: 

    protected void Page_Load(object sender, EventArgs e)
    {
    	System.Collections.IList visibleTables = MetaModel.Default.VisibleTables;
    	if (visibleTables.Count == 0)
    	{
    		throw new InvalidOperationException("There are no accessible tables...");
    	}
    
    	// adding your own table to the list
    	var tablesMain = from t in MetaModel.Default.VisibleTables
    					 where t.Attributes.OfType<LookupAttribute><LOOKUPATTRIBUTE>().SingleOrDefault() != null 
    					 select new MenuItem
    					 {
    						 ListActionPath = t.ListActionPath,
    						 DisplayName = t.DisplayName
    					 };
    
    	Menu1.DataSource = tablesMain;
    	Menu1.DataBind();
    }
    
     And here's the attribute: 
    [AttributeUsage(AttributeTargets.Class)]
    public class LookupAttribute : Attribute
    {
    	public Boolean LookupTable { get; private set; }
    
    	public LookupAttribute(Boolean lookupTable)
    	{
    		LookupTable = lookupTable;
    	}
    }
    Hope this helps [:D]
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 23, 2008 8:30 AM
  • User-1254308814 posted

    Sorry, I am not talking about columns I am talking about rows. I tried to add these Lookups to the partial class declarations but they have no impact on the actual displaying of the entity items.

     

    Thursday, October 23, 2008 2:46 PM
  • User-330204900 posted

    Hi Jwise this limits the table shown in the Default page where you have an attribute on the entity. If you want to e-mail me I send you a zipped up version of the project so can see it in action [:D]

    Thursday, October 23, 2008 3:23 PM
  • User-1254308814 posted

    You are right! I was missing a namespace and that caused a slight hiccup.[<:o)]
     

    <STRIKE>namespace cbadataModel
    {</STRIKE>
        /// <summary>
        /// Summary description for CBImageType
        /// </summary>
        [DisplayName("Image Type")]
        [Lookup(false)]
        public partial class CBImageType
        {
    
        }
        [DisplayName("Project Group")]
        [Lookup(false)]
        public partial class ProjectGroup
        {
    
        }
    
        [Lookup(false)]
        public partial class Section
        {
    
        }
        [DisplayName("Project Type")]
        [Lookup(false)]
        public partial class ProjectType
        {
    
        }
    
    <STRIKE>}</STRIKE>
     Thanks again
    Friday, October 24, 2008 1:50 AM
  • User-330204900 posted

    No problems have fun codeing [:D]

    Friday, October 24, 2008 4:26 AM
  • User-330204900 posted

    Note I've just written this up on my blog to make explination easyer [:D] Dynamic Data - Hiding Tables on the Default.aspx page

    Hope this helps [:D]

    Friday, October 24, 2008 12:59 PM